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/interpreter/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/interpreter-assembler.h" | 8 #include "src/compiler/interpreter-assembler.h" |
9 #include "src/factory.h" | 9 #include "src/factory.h" |
10 #include "src/interpreter/bytecodes.h" | 10 #include "src/interpreter/bytecodes.h" |
11 #include "src/zone.h" | 11 #include "src/zone.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace interpreter { | 15 namespace interpreter { |
16 | 16 |
17 using compiler::Node; | 17 using compiler::Node; |
18 #define __ assembler-> | 18 #define __ assembler-> |
19 | 19 |
20 | 20 |
21 Interpreter::Interpreter(Isolate* isolate) : isolate_(isolate) {} | 21 Interpreter::Interpreter(Isolate* isolate) |
22 : isolate_(isolate), initialized_(false) {} | |
23 | |
24 | |
25 // static | |
26 Handle<FixedArray> Interpreter::CreateUninitializedInterpreterTable( | |
27 Isolate* isolate) { | |
28 Handle<FixedArray> handler_table = isolate->factory()->NewFixedArray( | |
29 static_cast<int>(Bytecode::kLast) + 1, TENURED); | |
30 // We rely on the interpreter handler table being immovable, so check that | |
31 // it was allocated on the first page (which is always immovable). | |
32 DCHECK(isolate->heap()->old_space()->FirstPage()->Contains( | |
33 handler_table->address())); | |
34 for (int i = 0; i < static_cast<int>(Bytecode::kLast); i++) { | |
35 handler_table->set(i, isolate->builtins()->builtin(Builtins::kIllegal)); | |
36 } | |
37 return handler_table; | |
38 } | |
22 | 39 |
23 | 40 |
24 void Interpreter::Initialize(bool create_heap_objects) { | 41 void Interpreter::Initialize(bool create_heap_objects) { |
25 DCHECK(FLAG_ignition); | 42 DCHECK(FLAG_ignition); |
26 if (create_heap_objects) { | 43 if (initialized_) return; |
Hannes Payer (out of office)
2015/08/10 16:28:05
What is the purpose of initialized_?
rmcilroy
2015/08/10 16:37:03
It was for the code in test-interpreter to check w
| |
44 | |
45 Handle<FixedArray> handler_table = isolate_->factory()->interpreter_table(); | |
46 if (create_heap_objects || !IsInterpreterTableInitialized(handler_table)) { | |
27 Zone zone; | 47 Zone zone; |
28 HandleScope scope(isolate_); | 48 HandleScope scope(isolate_); |
29 Handle<FixedArray> handler_table = isolate_->factory()->NewFixedArray( | |
30 static_cast<int>(Bytecode::kLast) + 1, TENURED); | |
31 // We rely on the interpreter handler table being immovable, so check that | |
32 // it was allocated on the first page (which is always immovable). | |
33 DCHECK(isolate_->heap()->old_space()->FirstPage()->Contains( | |
34 handler_table->address())); | |
35 isolate_->heap()->public_set_interpreter_table(*handler_table); | |
36 | 49 |
37 #define GENERATE_CODE(Name, ...) \ | 50 #define GENERATE_CODE(Name, ...) \ |
38 { \ | 51 { \ |
39 compiler::InterpreterAssembler assembler(isolate_, &zone, \ | 52 compiler::InterpreterAssembler assembler(isolate_, &zone, \ |
40 Bytecode::k##Name); \ | 53 Bytecode::k##Name); \ |
41 Do##Name(&assembler); \ | 54 Do##Name(&assembler); \ |
42 Handle<Code> code = assembler.GenerateCode(); \ | 55 Handle<Code> code = assembler.GenerateCode(); \ |
43 handler_table->set(static_cast<int>(Bytecode::k##Name), *code); \ | 56 handler_table->set(static_cast<int>(Bytecode::k##Name), *code); \ |
44 } | 57 } |
45 BYTECODE_LIST(GENERATE_CODE) | 58 BYTECODE_LIST(GENERATE_CODE) |
46 #undef GENERATE_CODE | 59 #undef GENERATE_CODE |
47 } | 60 } |
61 | |
62 initialized_ = true; | |
48 } | 63 } |
49 | 64 |
50 | 65 |
66 bool Interpreter::IsInterpreterTableInitialized( | |
67 Handle<FixedArray> handler_table) { | |
68 DCHECK(handler_table->length() == static_cast<int>(Bytecode::kLast) + 1); | |
69 return handler_table->get(0) == | |
70 isolate_->builtins()->builtin(Builtins::kIllegal); | |
71 } | |
72 | |
73 | |
51 // LdaZero | 74 // LdaZero |
52 // | 75 // |
53 // Load literal '0' into the accumulator. | 76 // Load literal '0' into the accumulator. |
54 void Interpreter::DoLdaZero(compiler::InterpreterAssembler* assembler) { | 77 void Interpreter::DoLdaZero(compiler::InterpreterAssembler* assembler) { |
55 // TODO(rmcilroy) Implement. | 78 // TODO(rmcilroy) Implement. |
56 __ Dispatch(); | 79 __ Dispatch(); |
57 } | 80 } |
58 | 81 |
59 | 82 |
60 // LdaSmi8 <imm8> | 83 // LdaSmi8 <imm8> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 // | 192 // |
170 // Return the value in register 0. | 193 // Return the value in register 0. |
171 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { | 194 void Interpreter::DoReturn(compiler::InterpreterAssembler* assembler) { |
172 __ Return(); | 195 __ Return(); |
173 } | 196 } |
174 | 197 |
175 | 198 |
176 } // namespace interpreter | 199 } // namespace interpreter |
177 } // namespace internal | 200 } // namespace internal |
178 } // namespace v8 | 201 } // namespace v8 |
OLD | NEW |