OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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/extensions/ignition-statistics-extension.h" | |
6 | |
7 #include "src/interpreter/bytecodes.h" | |
8 #include "src/interpreter/interpreter.h" | |
9 #include "src/isolate.h" | |
10 | |
11 namespace v8 { | |
12 namespace internal { | |
13 | |
14 v8::Local<v8::FunctionTemplate> | |
15 IgnitionStatisticsExtension::GetNativeFunctionTemplate( | |
16 v8::Isolate* isolate, v8::Local<v8::String> name) { | |
17 DCHECK_EQ(strcmp(*v8::String::Utf8Value(name), "getIgnitionDispatchCounters"), | |
18 0); | |
19 return v8::FunctionTemplate::New( | |
20 isolate, IgnitionStatisticsExtension::DumpIgnitionDispatchCounters); | |
21 } | |
22 | |
23 const char* const IgnitionStatisticsExtension::kSource = | |
24 "native function getIgnitionDispatchCounters();"; | |
25 | |
26 void IgnitionStatisticsExtension::DumpIgnitionDispatchCounters( | |
rmcilroy
2016/04/21 14:17:29
Call this the same as the javascript function (or
Stefano Sanfilippo
2016/04/21 14:22:42
Oops, forgot to rename the method as well. Done.
| |
27 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
28 DCHECK_EQ(args.Length(), 0); | |
29 DCHECK(FLAG_trace_ignition_dispatches); | |
30 | |
31 using interpreter::Bytecode; | |
oth
2016/04/21 14:03:02
Is this needed?
Stefano Sanfilippo
2016/04/21 14:22:42
No, this is not needed, but using interpreter::Byt
rmcilroy
2016/04/21 14:33:30
+1 to removing this.
Stefano Sanfilippo
2016/04/22 13:00:49
Done contextually with extracting this piece of co
| |
32 | |
33 static const int kBytecodeCount = static_cast<int>(Bytecode::kLast) + 1; | |
oth
2016/04/21 14:03:02
This could be brittle as the code is reading direc
rmcilroy
2016/04/21 14:17:29
+1
Stefano Sanfilippo
2016/04/21 14:22:42
This is a very good point we might want to discuss
rmcilroy
2016/04/21 14:33:30
No I think we should do it here. The only other pl
Stefano Sanfilippo
2016/04/22 13:00:49
As discussed, we still need a getter for the raw p
| |
34 | |
35 v8::Isolate* isolate = args.GetIsolate(); | |
36 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
37 v8::Local<v8::Object> counters_map = v8::Object::New(isolate); | |
38 | |
39 uintptr_t* bytecode_dispatch_count_table = | |
40 reinterpret_cast<Isolate*>(isolate) | |
41 ->interpreter() | |
42 ->bytecode_dispatch_count_table(); | |
43 | |
44 for (int from_index = 0; from_index < kBytecodeCount; ++from_index) { | |
45 v8::Local<v8::Object> counters_row = v8::Object::New(args.GetIsolate()); | |
46 | |
47 for (int to_index = 0; to_index < kBytecodeCount; ++to_index) { | |
48 uintptr_t counter = | |
49 bytecode_dispatch_count_table[from_index * kBytecodeCount + to_index]; | |
50 if (counter > 0) { | |
51 Bytecode to_bytecode = interpreter::Bytecodes::FromByte(to_index); | |
52 std::string to_name = interpreter::Bytecodes::ToString(to_bytecode); | |
53 Local<v8::String> to_name_object = | |
54 v8::String::NewFromUtf8(isolate, to_name.c_str(), | |
55 NewStringType::kNormal) | |
56 .ToLocalChecked(); | |
57 Local<v8::Number> counter_object = | |
58 v8::Number::New(isolate, static_cast<uint32_t>(counter)); | |
rmcilroy
2016/04/21 14:17:29
You are casting to 32bits here - did casting to do
Stefano Sanfilippo
2016/04/21 14:22:42
Fixed.
| |
59 CHECK(counters_row->Set(context, to_name_object, counter_object) | |
rmcilroy
2016/04/21 14:17:29
No need for the CHECK here I don't think. IsJust w
Stefano Sanfilippo
2016/04/21 14:22:42
Done.
| |
60 .IsJust()); | |
61 } | |
62 } | |
63 | |
64 Bytecode from_bytecode = interpreter::Bytecodes::FromByte(from_index); | |
65 std::string from_name = interpreter::Bytecodes::ToString(from_bytecode); | |
66 Local<v8::String> from_name_object = | |
67 v8::String::NewFromUtf8(isolate, from_name.c_str(), | |
68 NewStringType::kNormal) | |
69 .ToLocalChecked(); | |
70 | |
71 CHECK(counters_map->Set(context, from_name_object, counters_row).IsJust()); | |
rmcilroy
2016/04/21 14:17:29
ditto
Stefano Sanfilippo
2016/04/21 14:22:42
Done.
| |
72 } | |
73 | |
74 args.GetReturnValue().Set(counters_map); | |
75 } | |
76 | |
77 } // namespace internal | |
78 } // namespace v8 | |
OLD | NEW |