OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/execution.h" | 8 #include "src/execution.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/interpreter/bytecode-array-builder.h" | 10 #include "src/interpreter/bytecode-array-builder.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 class InterpreterCallable { | 32 class InterpreterCallable { |
33 public: | 33 public: |
34 InterpreterCallable(Isolate* isolate, Handle<JSFunction> function) | 34 InterpreterCallable(Isolate* isolate, Handle<JSFunction> function) |
35 : isolate_(isolate), function_(function) {} | 35 : isolate_(isolate), function_(function) {} |
36 virtual ~InterpreterCallable() {} | 36 virtual ~InterpreterCallable() {} |
37 | 37 |
38 MaybeHandle<Object> operator()(A... args) { | 38 MaybeHandle<Object> operator()(A... args) { |
39 return CallInterpreter(isolate_, function_, args...); | 39 return CallInterpreter(isolate_, function_, args...); |
40 } | 40 } |
41 | 41 |
| 42 TypeFeedbackVector* vector() const { return function_->feedback_vector(); } |
| 43 |
42 private: | 44 private: |
43 Isolate* isolate_; | 45 Isolate* isolate_; |
44 Handle<JSFunction> function_; | 46 Handle<JSFunction> function_; |
45 }; | 47 }; |
46 | 48 |
47 namespace { | 49 namespace { |
48 const char kFunctionName[] = "f"; | 50 const char kFunctionName[] = "f"; |
49 } // namespace | 51 } // namespace |
50 | 52 |
51 class InterpreterTester { | 53 class InterpreterTester { |
52 public: | 54 public: |
53 InterpreterTester(Isolate* isolate, const char* source, | 55 InterpreterTester(Isolate* isolate, const char* source, |
54 MaybeHandle<BytecodeArray> bytecode, | 56 MaybeHandle<BytecodeArray> bytecode, |
55 MaybeHandle<TypeFeedbackVector> feedback_vector, | 57 MaybeHandle<TypeFeedbackMetadata> feedback_metadata, |
56 const char* filter); | 58 const char* filter); |
57 | 59 |
58 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, | 60 InterpreterTester(Isolate* isolate, Handle<BytecodeArray> bytecode, |
59 MaybeHandle<TypeFeedbackVector> feedback_vector = | 61 MaybeHandle<TypeFeedbackMetadata> feedback_metadata = |
60 MaybeHandle<TypeFeedbackVector>(), | 62 MaybeHandle<TypeFeedbackMetadata>(), |
61 const char* filter = kFunctionName); | 63 const char* filter = kFunctionName); |
62 | 64 |
63 InterpreterTester(Isolate* isolate, const char* source, | 65 InterpreterTester(Isolate* isolate, const char* source, |
64 const char* filter = kFunctionName); | 66 const char* filter = kFunctionName); |
65 | 67 |
66 virtual ~InterpreterTester(); | 68 virtual ~InterpreterTester(); |
67 | 69 |
68 template <class... A> | 70 template <class... A> |
69 InterpreterCallable<A...> GetCallable() { | 71 InterpreterCallable<A...> GetCallable() { |
70 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); | 72 return InterpreterCallable<A...>(isolate_, GetBytecodeFunction<A...>()); |
71 } | 73 } |
72 | 74 |
73 Local<Message> CheckThrowsReturnMessage(); | 75 Local<Message> CheckThrowsReturnMessage(); |
74 | 76 |
75 static Handle<Object> NewObject(const char* script); | 77 static Handle<Object> NewObject(const char* script); |
76 | 78 |
77 static Handle<String> GetName(Isolate* isolate, const char* name); | 79 static Handle<String> GetName(Isolate* isolate, const char* name); |
78 | 80 |
79 static std::string SourceForBody(const char* body); | 81 static std::string SourceForBody(const char* body); |
80 | 82 |
81 static std::string function_name(); | 83 static std::string function_name(); |
82 | 84 |
83 private: | 85 private: |
84 Isolate* isolate_; | 86 Isolate* isolate_; |
85 const char* source_; | 87 const char* source_; |
86 MaybeHandle<BytecodeArray> bytecode_; | 88 MaybeHandle<BytecodeArray> bytecode_; |
87 MaybeHandle<TypeFeedbackVector> feedback_vector_; | 89 MaybeHandle<TypeFeedbackMetadata> feedback_metadata_; |
88 | 90 |
89 template <class... A> | 91 template <class... A> |
90 Handle<JSFunction> GetBytecodeFunction() { | 92 Handle<JSFunction> GetBytecodeFunction() { |
91 Handle<JSFunction> function; | 93 Handle<JSFunction> function; |
92 if (source_) { | 94 if (source_) { |
93 CompileRun(source_); | 95 CompileRun(source_); |
94 v8::Local<v8::Context> context = | 96 v8::Local<v8::Context> context = |
95 v8::Isolate::GetCurrent()->GetCurrentContext(); | 97 v8::Isolate::GetCurrent()->GetCurrentContext(); |
96 Local<Function> api_function = | 98 Local<Function> api_function = |
97 Local<Function>::Cast(CcTest::global() | 99 Local<Function>::Cast(CcTest::global() |
98 ->Get(context, v8_str(kFunctionName)) | 100 ->Get(context, v8_str(kFunctionName)) |
99 .ToLocalChecked()); | 101 .ToLocalChecked()); |
100 function = Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); | 102 function = Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); |
101 } else { | 103 } else { |
102 int arg_count = sizeof...(A); | 104 int arg_count = sizeof...(A); |
103 std::string source("(function " + function_name() + "("); | 105 std::string source("(function " + function_name() + "("); |
104 for (int i = 0; i < arg_count; i++) { | 106 for (int i = 0; i < arg_count; i++) { |
105 source += i == 0 ? "a" : ", a"; | 107 source += i == 0 ? "a" : ", a"; |
106 } | 108 } |
107 source += "){})"; | 109 source += "){})"; |
108 function = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 110 function = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
109 *v8::Local<v8::Function>::Cast(CompileRun(source.c_str())))); | 111 *v8::Local<v8::Function>::Cast(CompileRun(source.c_str())))); |
110 function->ReplaceCode( | 112 function->ReplaceCode( |
111 *isolate_->builtins()->InterpreterEntryTrampoline()); | 113 *isolate_->builtins()->InterpreterEntryTrampoline()); |
112 } | 114 } |
113 | 115 |
114 if (!bytecode_.is_null()) { | 116 if (!bytecode_.is_null()) { |
115 function->shared()->set_function_data(*bytecode_.ToHandleChecked()); | 117 function->shared()->set_function_data(*bytecode_.ToHandleChecked()); |
116 } | 118 } |
117 if (!feedback_vector_.is_null()) { | 119 if (!feedback_metadata_.is_null()) { |
118 function->literals()->set_feedback_vector( | 120 // TODO(mvstanton): The call to ClearOptimizedCodeMap can be removed |
119 *feedback_vector_.ToHandleChecked()); | 121 // when we stop storing literals in the optimized code map (upcoming CL). |
| 122 function->shared()->ClearOptimizedCodeMap(); |
| 123 function->shared()->set_feedback_metadata( |
| 124 *feedback_metadata_.ToHandleChecked()); |
| 125 JSFunction::EnsureLiterals(function); |
120 } | 126 } |
121 return function; | 127 return function; |
122 } | 128 } |
123 | 129 |
124 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); | 130 DISALLOW_COPY_AND_ASSIGN(InterpreterTester); |
125 }; | 131 }; |
126 | 132 |
127 } // namespace interpreter | 133 } // namespace interpreter |
128 } // namespace internal | 134 } // namespace internal |
129 } // namespace v8 | 135 } // namespace v8 |
OLD | NEW |