Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: src/interpreter/interpreter.cc

Issue 2560893002: [interpreter] Avoid code duplication in Interpreter::Initialize(). (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/interpreter/interpreter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <fstream> 7 #include <fstream>
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/ast/prettyprinter.h" 10 #include "src/ast/prettyprinter.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 } 66 }
67 67
68 // Generate bytecode handlers for all bytecodes and scales. 68 // Generate bytecode handlers for all bytecodes and scales.
69 const OperandScale kOperandScales[] = { 69 const OperandScale kOperandScales[] = {
70 #define VALUE(Name, _) OperandScale::k##Name, 70 #define VALUE(Name, _) OperandScale::k##Name,
71 OPERAND_SCALE_LIST(VALUE) 71 OPERAND_SCALE_LIST(VALUE)
72 #undef VALUE 72 #undef VALUE
73 }; 73 };
74 74
75 for (OperandScale operand_scale : kOperandScales) { 75 for (OperandScale operand_scale : kOperandScales) {
76 #define GENERATE_CODE(Name, ...) \ 76 #define GENERATE_CODE(Name, ...) \
77 { \ 77 InstallBytecodeHandler(&zone, Bytecode::k##Name, operand_scale, \
78 if (Bytecodes::BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \ 78 &Interpreter::Do##Name);
79 InterpreterDispatchDescriptor descriptor(isolate_); \
80 compiler::CodeAssemblerState state( \
81 isolate_, &zone, descriptor, \
82 Code::ComputeFlags(Code::BYTECODE_HANDLER), \
83 Bytecodes::ToString(Bytecode::k##Name), \
84 Bytecodes::ReturnCount(Bytecode::k##Name)); \
85 InterpreterAssembler assembler(&state, Bytecode::k##Name, \
86 operand_scale); \
87 Do##Name(&assembler); \
88 Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state); \
89 size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \
90 dispatch_table_[index] = code->entry(); \
91 TraceCodegen(code); \
92 PROFILE( \
93 isolate_, \
94 CodeCreateEvent( \
95 CodeEventListener::BYTECODE_HANDLER_TAG, \
96 AbstractCode::cast(*code), \
97 Bytecodes::ToString(Bytecode::k##Name, operand_scale).c_str())); \
98 } \
99 }
100 BYTECODE_LIST(GENERATE_CODE) 79 BYTECODE_LIST(GENERATE_CODE)
101 #undef GENERATE_CODE 80 #undef GENERATE_CODE
102 } 81 }
103 82
104 // Fill unused entries will the illegal bytecode handler. 83 // Fill unused entries will the illegal bytecode handler.
105 size_t illegal_index = 84 size_t illegal_index =
106 GetDispatchTableIndex(Bytecode::kIllegal, OperandScale::kSingle); 85 GetDispatchTableIndex(Bytecode::kIllegal, OperandScale::kSingle);
107 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) { 86 for (size_t index = 0; index < arraysize(dispatch_table_); ++index) {
108 if (dispatch_table_[index] == nullptr) { 87 if (dispatch_table_[index] == nullptr) {
109 dispatch_table_[index] = dispatch_table_[illegal_index]; 88 dispatch_table_[index] = dispatch_table_[illegal_index];
110 } 89 }
111 } 90 }
112 91
113 // Initialization should have been successful. 92 // Initialization should have been successful.
114 DCHECK(IsDispatchTableInitialized()); 93 DCHECK(IsDispatchTableInitialized());
115 } 94 }
116 95
96 void Interpreter::InstallBytecodeHandler(Zone* zone, Bytecode bytecode,
97 OperandScale operand_scale,
98 BytecodeGeneratorFunc generator) {
99 if (!Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) return;
100
101 InterpreterDispatchDescriptor descriptor(isolate_);
102 compiler::CodeAssemblerState state(
103 isolate_, zone, descriptor, Code::ComputeFlags(Code::BYTECODE_HANDLER),
104 Bytecodes::ToString(bytecode), Bytecodes::ReturnCount(bytecode));
105 InterpreterAssembler assembler(&state, bytecode, operand_scale);
106 (this->*generator)(&assembler);
107 Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state);
108 size_t index = GetDispatchTableIndex(bytecode, operand_scale);
109 dispatch_table_[index] = code->entry();
110 TraceCodegen(code);
111 PROFILE(isolate_, CodeCreateEvent(
112 CodeEventListener::BYTECODE_HANDLER_TAG,
113 AbstractCode::cast(*code),
114 Bytecodes::ToString(bytecode, operand_scale).c_str()));
115 }
116
117 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode, 117 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode,
118 OperandScale operand_scale) { 118 OperandScale operand_scale) {
119 DCHECK(IsDispatchTableInitialized()); 119 DCHECK(IsDispatchTableInitialized());
120 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale)); 120 DCHECK(Bytecodes::BytecodeHasHandler(bytecode, operand_scale));
121 size_t index = GetDispatchTableIndex(bytecode, operand_scale); 121 size_t index = GetDispatchTableIndex(bytecode, operand_scale);
122 Address code_entry = dispatch_table_[index]; 122 Address code_entry = dispatch_table_[index];
123 return Code::GetCodeFromTargetAddress(code_entry); 123 return Code::GetCodeFromTargetAddress(code_entry);
124 } 124 }
125 125
126 // static 126 // static
(...skipping 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after
2866 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, 2866 __ StoreObjectField(generator, JSGeneratorObject::kContinuationOffset,
2867 __ SmiTag(new_state)); 2867 __ SmiTag(new_state));
2868 __ SetAccumulator(old_state); 2868 __ SetAccumulator(old_state);
2869 2869
2870 __ Dispatch(); 2870 __ Dispatch();
2871 } 2871 }
2872 2872
2873 } // namespace interpreter 2873 } // namespace interpreter
2874 } // namespace internal 2874 } // namespace internal
2875 } // namespace v8 2875 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698