| 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/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 static_cast<uint8_t>(((x++) >> kBitsPerByte) & 0xff) | 102 static_cast<uint8_t>(((x++) >> kBitsPerByte) & 0xff) |
| 103 #elif defined(V8_TARGET_BIG_ENDIAN) | 103 #elif defined(V8_TARGET_BIG_ENDIAN) |
| 104 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ | 104 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ |
| 105 static_cast<uint8_t>((x) & 0xff) | 105 static_cast<uint8_t>((x) & 0xff) |
| 106 #define U16I(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ | 106 #define U16I(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ |
| 107 static_cast<uint8_t>((x++) & 0xff) | 107 static_cast<uint8_t>((x++) & 0xff) |
| 108 #else | 108 #else |
| 109 #error Unknown byte ordering | 109 #error Unknown byte ordering |
| 110 #endif | 110 #endif |
| 111 | 111 |
| 112 #define XSTR(A) #A |
| 113 #define STR(A) XSTR(A) |
| 114 |
| 112 #define COMMA() , | 115 #define COMMA() , |
| 113 #define SPACE() | 116 #define SPACE() |
| 117 #define UNIQUE_VAR() "var a" STR(__COUNTER__) " = 0;\n" |
| 114 | 118 |
| 115 #define REPEAT_2(SEP, ...) \ | 119 #define REPEAT_2(SEP, ...) \ |
| 116 __VA_ARGS__ SEP() __VA_ARGS__ | 120 __VA_ARGS__ SEP() __VA_ARGS__ |
| 117 #define REPEAT_4(SEP, ...) \ | 121 #define REPEAT_4(SEP, ...) \ |
| 118 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) | 122 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) |
| 119 #define REPEAT_8(SEP, ...) \ | 123 #define REPEAT_8(SEP, ...) \ |
| 120 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__) | 124 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__) |
| 121 #define REPEAT_16(SEP, ...) \ | 125 #define REPEAT_16(SEP, ...) \ |
| 122 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) | 126 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) |
| 123 #define REPEAT_32(SEP, ...) \ | 127 #define REPEAT_32(SEP, ...) \ |
| 124 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) | 128 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) |
| 125 #define REPEAT_64(SEP, ...) \ | 129 #define REPEAT_64(SEP, ...) \ |
| 126 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) | 130 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) |
| 127 #define REPEAT_128(SEP, ...) \ | 131 #define REPEAT_128(SEP, ...) \ |
| 128 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) | 132 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) |
| 129 #define REPEAT_256(SEP, ...) \ | 133 #define REPEAT_256(SEP, ...) \ |
| 130 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__) | 134 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__) |
| 131 | 135 |
| 132 #define REPEAT_127(SEP, ...) \ | 136 #define REPEAT_127(SEP, ...) \ |
| 133 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) SEP() \ | 137 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) SEP() \ |
| 134 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) SEP() \ | 138 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) SEP() \ |
| 135 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() \ | 139 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() \ |
| 136 __VA_ARGS__ | 140 __VA_ARGS__ |
| 137 | 141 |
| 142 #define REPEAT_249(SEP, ...) \ |
| 143 REPEAT_127(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) SEP() \ |
| 144 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) SEP() \ |
| 145 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) |
| 146 |
| 147 #define REPEAT_249_UNIQUE_VARS() \ |
| 148 UNIQUE_VAR() REPEAT_127(UNIQUE_VAR) UNIQUE_VAR() REPEAT_64(UNIQUE_VAR) \ |
| 149 UNIQUE_VAR() REPEAT_32(UNIQUE_VAR) UNIQUE_VAR() REPEAT_16(UNIQUE_VAR) \ |
| 150 UNIQUE_VAR() REPEAT_8(UNIQUE_VAR) UNIQUE_VAR() REPEAT_2(UNIQUE_VAR) |
| 151 |
| 138 // Structure for containing expected bytecode snippets. | 152 // Structure for containing expected bytecode snippets. |
| 139 template<typename T, int C = 6> | 153 template<typename T, int C = 6> |
| 140 struct ExpectedSnippet { | 154 struct ExpectedSnippet { |
| 141 const char* code_snippet; | 155 const char* code_snippet; |
| 142 int frame_size; | 156 int frame_size; |
| 143 int parameter_count; | 157 int parameter_count; |
| 144 int bytecode_length; | 158 int bytecode_length; |
| 145 const uint8_t bytecode[2048]; | 159 const uint8_t bytecode[2048]; |
| 146 int constant_count; | 160 int constant_count; |
| 147 T constants[C]; | 161 T constants[C]; |
| (...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4009 BytecodeGeneratorHelper helper; | 4023 BytecodeGeneratorHelper helper; |
| 4010 Zone zone; | 4024 Zone zone; |
| 4011 | 4025 |
| 4012 FeedbackVectorSpec feedback_spec(&zone); | 4026 FeedbackVectorSpec feedback_spec(&zone); |
| 4013 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); | 4027 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); |
| 4014 | 4028 |
| 4015 Handle<i::TypeFeedbackVector> vector = | 4029 Handle<i::TypeFeedbackVector> vector = |
| 4016 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 4030 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
| 4017 | 4031 |
| 4018 int closure = Register::function_closure().index(); | 4032 int closure = Register::function_closure().index(); |
| 4033 int new_target = Register::new_target().index(); |
| 4019 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 4034 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
| 4035 |
| 4036 // The wide check below relies on MIN_CONTEXT_SLOTS + 3 + 249 == 256, if this |
| 4037 // ever changes, the REPEAT_XXX should be changed to output the correct number |
| 4038 // of unique variables to trigger the wide slot load / store. |
| 4039 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS + 3 + 249 == 256); |
| 4040 int wide_slot = first_context_slot + 3; |
| 4041 |
| 4020 ExpectedSnippet<InstanceType> snippets[] = { | 4042 ExpectedSnippet<InstanceType> snippets[] = { |
| 4021 {"var a; return function() { a = 1; };", | 4043 {"var a; return function() { a = 1; };", |
| 4022 1 * kPointerSize, | 4044 1 * kPointerSize, |
| 4023 1, | 4045 1, |
| 4024 11, | 4046 11, |
| 4025 { | 4047 { |
| 4026 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 4048 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
| 4027 R(closure), U8(1), // | 4049 R(closure), U8(1), // |
| 4028 B(PushContext), R(0), // | 4050 B(PushContext), R(0), // |
| 4029 B(CreateClosure), U8(0), U8(0), // | 4051 B(CreateClosure), U8(0), U8(0), // |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4102 B(LdaTheHole), // | 4124 B(LdaTheHole), // |
| 4103 B(StaContextSlot), R(1), U8(first_context_slot), // | 4125 B(StaContextSlot), R(1), U8(first_context_slot), // |
| 4104 B(LdaSmi8), U8(2), // | 4126 B(LdaSmi8), U8(2), // |
| 4105 B(StaContextSlot), R(1), U8(first_context_slot), // | 4127 B(StaContextSlot), R(1), U8(first_context_slot), // |
| 4106 B(CreateClosure), U8(1), U8(0), // | 4128 B(CreateClosure), U8(1), U8(0), // |
| 4107 B(Return), // | 4129 B(Return), // |
| 4108 }, | 4130 }, |
| 4109 2, | 4131 2, |
| 4110 {InstanceType::FIXED_ARRAY_TYPE, | 4132 {InstanceType::FIXED_ARRAY_TYPE, |
| 4111 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 4133 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
| 4134 {"'use strict';\n" |
| 4135 REPEAT_249_UNIQUE_VARS() |
| 4136 "eval();" |
| 4137 "var b = 100;" |
| 4138 "return b", |
| 4139 3 * kPointerSize, |
| 4140 1, |
| 4141 1041, |
| 4142 { |
| 4143 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // |
| 4144 U8(1), // |
| 4145 B(PushContext), R(0), // |
| 4146 B(Ldar), THIS(1), // |
| 4147 B(StaContextSlot), R(0), U8(first_context_slot), // |
| 4148 B(CreateUnmappedArguments), // |
| 4149 B(StaContextSlot), R(0), U8(first_context_slot + 1), // |
| 4150 B(Ldar), R(new_target), // |
| 4151 B(StaContextSlot), R(0), U8(first_context_slot + 2), // |
| 4152 REPEAT_249(COMMA, // |
| 4153 B(LdaZero), // |
| 4154 B(StaContextSlot), R(0), U8(wide_slot++)), // |
| 4155 B(LdaUndefined), // |
| 4156 B(Star), R(2), // |
| 4157 B(LdaGlobalStrict), U8(0), U8(1), // |
| 4158 B(Star), R(1), // |
| 4159 B(Call), R(1), R(2), U8(0), U8(0), // |
| 4160 B(LdaSmi8), U8(100), // |
| 4161 B(StaContextSlotWide), R(0), U16(256), // |
| 4162 B(LdaContextSlotWide), R(0), U16(256), // |
| 4163 B(Return), // |
| 4164 }, |
| 4165 1, |
| 4166 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, |
| 4112 }; | 4167 }; |
| 4113 | 4168 |
| 4114 for (size_t i = 0; i < arraysize(snippets); i++) { | 4169 for (size_t i = 0; i < arraysize(snippets); i++) { |
| 4115 Handle<BytecodeArray> bytecode_array = | 4170 Handle<BytecodeArray> bytecode_array = |
| 4116 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4171 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
| 4117 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4172 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 4118 } | 4173 } |
| 4119 } | 4174 } |
| 4120 | 4175 |
| 4121 | 4176 |
| (...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6266 std::string(function_epilogue); | 6321 std::string(function_epilogue); |
| 6267 Handle<BytecodeArray> bytecode_array = | 6322 Handle<BytecodeArray> bytecode_array = |
| 6268 helper.MakeBytecode(script.c_str(), "t", "f"); | 6323 helper.MakeBytecode(script.c_str(), "t", "f"); |
| 6269 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6324 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
| 6270 } | 6325 } |
| 6271 } | 6326 } |
| 6272 | 6327 |
| 6273 } // namespace interpreter | 6328 } // namespace interpreter |
| 6274 } // namespace internal | 6329 } // namespace internal |
| 6275 } // namespace v8 | 6330 } // namespace v8 |
| OLD | NEW |