| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent be75795 commit b56c8ad
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | 29 | # Reset this number to 0 on major V8 upgrades. | |
| 30 | 30 | # Increment by one for each non-official patch applied to deps/v8. | |
| 31 | - 'v8_embedder_string': '-node.17', | ||
| 31 | + 'v8_embedder_string': '-node.18', | ||
| 32 | 32 | ||
| 33 | 33 | # Enable disassembler for `--print-code` v8 options | |
| 34 | 34 | 'v8_enable_disassembler': 1, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,6 +82,7 @@ Jan de Mooij <jandemooij@gmail.com> | |||
| 82 | 82 | Jan Krems <jan.krems@gmail.com> | |
| 83 | 83 | Jay Freeman <saurik@saurik.com> | |
| 84 | 84 | James Pike <g00gle@chilon.net> | |
| 85 | + James M Snell <jasnell@gmail.com> | ||
| 85 | 86 | Jianghua Yang <jianghua.yjh@alibaba-inc.com> | |
| 86 | 87 | Joel Stanley <joel@jms.id.au> | |
| 87 | 88 | Johan Bergström <johan@bergstroem.nu> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1420,6 +1420,7 @@ v8_source_set("v8_base") { | |||
| 1420 | 1420 | "src/builtins/builtins-sharedarraybuffer.cc", | |
| 1421 | 1421 | "src/builtins/builtins-string.cc", | |
| 1422 | 1422 | "src/builtins/builtins-symbol.cc", | |
| 1423 | + "src/builtins/builtins-trace.cc", | ||
| 1423 | 1424 | "src/builtins/builtins-typedarray.cc", | |
| 1424 | 1425 | "src/builtins/builtins-utils.h", | |
| 1425 | 1426 | "src/builtins/builtins.cc", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -626,6 +626,7 @@ | |||
| 626 | 626 | '../src/builtins/builtins-intl.cc', | |
| 627 | 627 | '../src/builtins/builtins-intl.h', | |
| 628 | 628 | '../src/builtins/builtins-symbol.cc', | |
| 629 | + '../src/builtins/builtins-trace.cc', | ||
| 629 | 630 | '../src/builtins/builtins-typedarray.cc', | |
| 630 | 631 | '../src/builtins/builtins-utils.h', | |
| 631 | 632 | '../src/builtins/builtins.cc', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4947,6 +4947,15 @@ bool Genesis::InstallExtraNatives() { | |||
| 4947 | 4947 | ||
| 4948 | 4948 | Handle<JSObject> extras_binding = | |
| 4949 | 4949 | factory()->NewJSObject(isolate()->object_function()); | |
| 4950 | + | ||
| 4951 | + // binding.isTraceCategoryenabled(category) | ||
| 4952 | + SimpleInstallFunction(extras_binding, "isTraceCategoryEnabled", | ||
| 4953 | + Builtins::kIsTraceCategoryEnabled, 1, true); | ||
| 4954 | + | ||
| 4955 | + // binding.trace(phase, category, name, id, data) | ||
| 4956 | + SimpleInstallFunction(extras_binding, "trace", Builtins::kTrace, 5, | ||
| 4957 | + true); | ||
| 4958 | + | ||
| 4950 | 4959 | native_context()->set_extras_binding_object(*extras_binding); | |
| 4951 | 4960 | ||
| 4952 | 4961 | for (int i = ExtraNatives::GetDebuggerCount(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1247,7 +1247,11 @@ namespace internal { | |||
| 1247 | 1247 | /* #sec-%asyncfromsynciteratorprototype%.return */ \ | |
| 1248 | 1248 | TFJ(AsyncFromSyncIteratorPrototypeReturn, 1, kValue) \ | |
| 1249 | 1249 | /* #sec-async-iterator-value-unwrap-functions */ \ | |
| 1250 | - TFJ(AsyncIteratorValueUnwrap, 1, kValue) | ||
| 1250 | + TFJ(AsyncIteratorValueUnwrap, 1, kValue) \ | ||
| 1251 | + \ | ||
| 1252 | + /* Trace */ \ | ||
| 1253 | + CPP(IsTraceCategoryEnabled) \ | ||
| 1254 | + CPP(Trace) | ||
| 1251 | 1255 | ||
| 1252 | 1256 | #ifdef V8_INTL_SUPPORT | |
| 1253 | 1257 | #define BUILTIN_LIST(CPP, API, TFJ, TFC, TFS, TFH, ASM) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,191 @@ | |||
| 1 | + // Copyright 2018 the V8 project authors. All rights reserved. | ||
| 2 | + // Use of this source code is governed by a BSD-style license that can be | ||
| 3 | + // found in the LICENSE file. | ||
| 4 | + | ||
| 5 | + #include "src/api.h" | ||
| 6 | + #include "src/builtins/builtins-utils.h" | ||
| 7 | + #include "src/builtins/builtins.h" | ||
| 8 | + #include "src/counters.h" | ||
| 9 | + #include "src/json-stringifier.h" | ||
| 10 | + #include "src/objects-inl.h" | ||
| 11 | + | ||
| 12 | + namespace v8 { | ||
| 13 | + namespace internal { | ||
| 14 | + | ||
| 15 | + namespace { | ||
| 16 | + | ||
| 17 | + using v8::tracing::TracedValue; | ||
| 18 | + | ||
| 19 | + #define MAX_STACK_LENGTH 100 | ||
| 20 | + | ||
| 21 | + class MaybeUtf8 { | ||
| 22 | + public: | ||
| 23 | + explicit MaybeUtf8(Isolate* isolate, Handle<String> string) : buf_(data_) { | ||
| 24 | + string = String::Flatten(string); | ||
| 25 | + int len; | ||
| 26 | + if (string->IsOneByteRepresentation()) { | ||
| 27 | + // Technically this allows unescaped latin1 characters but the trace | ||
| 28 | + // events mechanism currently does the same and the current consuming | ||
| 29 | + // tools are tolerant of it. A more correct approach here would be to | ||
| 30 | + // escape non-ascii characters but this is easier and faster. | ||
| 31 | + len = string->length(); | ||
| 32 | + AllocateSufficientSpace(len); | ||
| 33 | + if (len > 0) { | ||
| 34 | + // Why copy? Well, the trace event mechanism requires null-terminated | ||
| 35 | + // strings, the bytes we get from SeqOneByteString are not. buf_ is | ||
| 36 | + // guaranteed to be null terminated. | ||
| 37 | + memcpy(buf_, Handle<SeqOneByteString>::cast(string)->GetChars(), len); | ||
| 38 | + } | ||
| 39 | + } else { | ||
| 40 | + Local<v8::String> local = Utils::ToLocal(string); | ||
| 41 | + len = local->Utf8Length(); | ||
| 42 | + AllocateSufficientSpace(len); | ||
| 43 | + if (len > 0) { | ||
| 44 | + local->WriteUtf8(reinterpret_cast<char*>(buf_)); | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + buf_[len] = 0; | ||
| 48 | + } | ||
| 49 | + const char* operator*() const { return reinterpret_cast<const char*>(buf_); } | ||
| 50 | + | ||
| 51 | + private: | ||
| 52 | + void AllocateSufficientSpace(int len) { | ||
| 53 | + if (len + 1 > MAX_STACK_LENGTH) { | ||
| 54 | + allocated_.reset(new uint8_t[len + 1]); | ||
| 55 | + buf_ = allocated_.get(); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + // In the most common cases, the buffer here will be stack allocated. | ||
| 60 | + // A heap allocation will only occur if the data is more than MAX_STACK_LENGTH | ||
| 61 | + // Given that this is used primarily for trace event categories and names, | ||
| 62 | + // the MAX_STACK_LENGTH should be more than enough. | ||
| 63 | + uint8_t* buf_; | ||
| 64 | + uint8_t data_[MAX_STACK_LENGTH]; | ||
| 65 | + std::unique_ptr<uint8_t> allocated_; | ||
| 66 | + }; | ||
| 67 | + | ||
| 68 | + class JsonTraceValue : public ConvertableToTraceFormat { | ||
| 69 | + public: | ||
| 70 | + explicit JsonTraceValue(Isolate* isolate, Handle<String> object) { | ||
| 71 | + // object is a JSON string serialized using JSON.stringify() from within | ||
| 72 | + // the BUILTIN(Trace) method. This may (likely) contain UTF8 values so | ||
| 73 | + // to grab the appropriate buffer data we have to serialize it out. We | ||
| 74 | + // hold on to the bits until the AppendAsTraceFormat method is called. | ||
| 75 | + MaybeUtf8 data(isolate, object); | ||
| 76 | + data_ = *data; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + void AppendAsTraceFormat(std::string* out) const override { *out += data_; } | ||
| 80 | + | ||
| 81 | + private: | ||
| 82 | + std::string data_; | ||
| 83 | + }; | ||
| 84 | + | ||
| 85 | + const uint8_t* GetCategoryGroupEnabled(Isolate* isolate, | ||
| 86 | + Handle<String> string) { | ||
| 87 | + MaybeUtf8 category(isolate, string); | ||
| 88 | + return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(*category); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + #undef MAX_STACK_LENGTH | ||
| 92 | + | ||
| 93 | + } // namespace | ||
| 94 | + | ||
| 95 | + // Builins::kIsTraceCategoryEnabled(category) : bool | ||
| 96 | + BUILTIN(IsTraceCategoryEnabled) { | ||
| 97 | + HandleScope scope(isolate); | ||
| 98 | + Handle<Object> category = args.atOrUndefined(isolate, 1); | ||
| 99 | + if (!category->IsString()) { | ||
| 100 | + THROW_NEW_ERROR_RETURN_FAILURE( | ||
| 101 | + isolate, NewTypeError(MessageTemplate::kTraceEventCategoryError)); | ||
| 102 | + } | ||
| 103 | + return isolate->heap()->ToBoolean( | ||
| 104 | + *GetCategoryGroupEnabled(isolate, Handle<String>::cast(category))); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + // Builtins::kTrace(phase, category, name, id, data) : bool | ||
| 108 | + BUILTIN(Trace) { | ||
| 109 | + HandleScope handle_scope(isolate); | ||
| 110 | + | ||
| 111 | + Handle<Object> phase_arg = args.atOrUndefined(isolate, 1); | ||
| 112 | + Handle<Object> category = args.atOrUndefined(isolate, 2); | ||
| 113 | + Handle<Object> name_arg = args.atOrUndefined(isolate, 3); | ||
| 114 | + Handle<Object> id_arg = args.atOrUndefined(isolate, 4); | ||
| 115 | + Handle<Object> data_arg = args.atOrUndefined(isolate, 5); | ||
| 116 | + | ||
| 117 | + const uint8_t* category_group_enabled = | ||
| 118 | + GetCategoryGroupEnabled(isolate, Handle<String>::cast(category)); | ||
| 119 | + | ||
| 120 | + // Exit early if the category group is not enabled. | ||
| 121 | + if (!*category_group_enabled) { | ||
| 122 | + return isolate->heap()->false_value(); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + if (!phase_arg->IsNumber()) { | ||
| 126 | + THROW_NEW_ERROR_RETURN_FAILURE( | ||
| 127 | + isolate, NewTypeError(MessageTemplate::kTraceEventPhaseError)); | ||
| 128 | + } | ||
| 129 | + if (!category->IsString()) { | ||
| 130 | + THROW_NEW_ERROR_RETURN_FAILURE( | ||
| 131 | + isolate, NewTypeError(MessageTemplate::kTraceEventCategoryError)); | ||
| 132 | + } | ||
| 133 | + if (!name_arg->IsString()) { | ||
| 134 | + THROW_NEW_ERROR_RETURN_FAILURE( | ||
| 135 | + isolate, NewTypeError(MessageTemplate::kTraceEventNameError)); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + uint32_t flags = TRACE_EVENT_FLAG_COPY; | ||
| 139 | + int32_t id = 0; | ||
| 140 | + if (!id_arg->IsNullOrUndefined(isolate)) { | ||
| 141 | + if (!id_arg->IsNumber()) { | ||
| 142 | + THROW_NEW_ERROR_RETURN_FAILURE( | ||
| 143 | + isolate, NewTypeError(MessageTemplate::kTraceEventIDError)); | ||
| 144 | + } | ||
| 145 | + flags |= TRACE_EVENT_FLAG_HAS_ID; | ||
| 146 | + id = DoubleToInt32(id_arg->Number()); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + Handle<String> name_str = Handle<String>::cast(name_arg); | ||
| 150 | + if (name_str->length() == 0) { | ||
| 151 | + THROW_NEW_ERROR_RETURN_FAILURE( | ||
| 152 | + isolate, NewTypeError(MessageTemplate::kTraceEventNameLengthError)); | ||
| 153 | + } | ||
| 154 | + MaybeUtf8 name(isolate, name_str); | ||
| 155 | + | ||
| 156 | + // We support passing one additional trace event argument with the | ||
| 157 | + // name "data". Any JSON serializable value may be passed. | ||
| 158 | + static const char* arg_name = "data"; | ||
| 159 | + int32_t num_args = 0; | ||
| 160 | + uint8_t arg_type; | ||
| 161 | + uint64_t arg_value; | ||
| 162 | + | ||
| 163 | + if (!data_arg->IsUndefined(isolate)) { | ||
| 164 | + // Serializes the data argument as a JSON string, which is then | ||
| 165 | + // copied into an object. This eliminates duplicated code but | ||
| 166 | + // could have perf costs. It is also subject to all the same | ||
| 167 | + // limitations as JSON.stringify() as it relates to circular | ||
| 168 | + // references and value limitations (e.g. BigInt is not supported). | ||
| 169 | + JsonStringifier stringifier(isolate); | ||
| 170 | + Handle<Object> result; | ||
| 171 | + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | ||
| 172 | + isolate, result, | ||
| 173 | + stringifier.Stringify(data_arg, isolate->factory()->undefined_value(), | ||
| 174 | + isolate->factory()->undefined_value())); | ||
| 175 | + std::unique_ptr<JsonTraceValue> traced_value; | ||
| 176 | + traced_value.reset( | ||
| 177 | + new JsonTraceValue(isolate, Handle<String>::cast(result))); | ||
| 178 | + tracing::SetTraceValue(std::move(traced_value), &arg_type, &arg_value); | ||
| 179 | + num_args++; | ||
| 180 | + } | ||
| 181 | + | ||
| 182 | + TRACE_EVENT_API_ADD_TRACE_EVENT( | ||
| 183 | + static_cast<char>(DoubleToInt32(phase_arg->Number())), | ||
| 184 | + category_group_enabled, *name, tracing::kGlobalScope, id, tracing::kNoId, | ||
| 185 | + num_args, &arg_name, &arg_type, &arg_value, flags); | ||
| 186 | + | ||
| 187 | + return isolate->heap()->true_value(); | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + } // namespace internal | ||
| 191 | + } // namespace v8 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -621,6 +621,9 @@ bool BuiltinHasNoSideEffect(Builtins::Name id) { | |||
| 621 | 621 | case Builtins::kArrayMap: | |
| 622 | 622 | case Builtins::kArrayReduce: | |
| 623 | 623 | case Builtins::kArrayReduceRight: | |
| 624 | + // Trace builtins | ||
| 625 | + case Builtins::kIsTraceCategoryEnabled: | ||
| 626 | + case Builtins::kTrace: | ||
| 624 | 627 | // TypedArray builtins. | |
| 625 | 628 | case Builtins::kTypedArrayConstructor: | |
| 626 | 629 | case Builtins::kTypedArrayPrototypeBuffer: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -755,7 +755,14 @@ class ErrorUtils : public AllStatic { | |||
| 755 | 755 | T(DataCloneDeserializationError, "Unable to deserialize cloned data.") \ | |
| 756 | 756 | T(DataCloneDeserializationVersionError, \ | |
| 757 | 757 | "Unable to deserialize cloned data due to invalid or unsupported " \ | |
| 758 | - "version.") | ||
| 758 | + "version.") \ | ||
| 759 | + /* Builtins-Trace Errors */ \ | ||
| 760 | + T(TraceEventCategoryError, "Trace event category must be a string.") \ | ||
| 761 | + T(TraceEventNameError, "Trace event name must be a string.") \ | ||
| 762 | + T(TraceEventNameLengthError, \ | ||
| 763 | + "Trace event name must not be an empty string.") \ | ||
| 764 | + T(TraceEventPhaseError, "Trace event phase must be a number.") \ | ||
| 765 | + T(TraceEventIDError, "Trace event id must be a number.") | ||
| 759 | 766 | ||
| 760 | 767 | class MessageTemplate { | |
| 761 | 768 | public: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments