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/base/atomic-utils.h" | 5 #include "src/base/atomic-utils.h" |
6 #include "src/macro-assembler.h" | 6 #include "src/macro-assembler.h" |
7 #include "src/objects.h" | 7 #include "src/objects.h" |
8 #include "src/property-descriptor.h" | 8 #include "src/property-descriptor.h" |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 285 } |
286 | 286 |
287 bool LinkFunction(Handle<Code> unlinked, | 287 bool LinkFunction(Handle<Code> unlinked, |
288 const std::vector<Handle<Code>>& code_targets, | 288 const std::vector<Handle<Code>>& code_targets, |
289 Code::Kind kind) { | 289 Code::Kind kind) { |
290 bool modified = false; | 290 bool modified = false; |
291 int mode_mask = RelocInfo::kCodeTargetMask; | 291 int mode_mask = RelocInfo::kCodeTargetMask; |
292 AllowDeferredHandleDereference embedding_raw_address; | 292 AllowDeferredHandleDereference embedding_raw_address; |
293 for (RelocIterator it(*unlinked, mode_mask); !it.done(); it.next()) { | 293 for (RelocIterator it(*unlinked, mode_mask); !it.done(); it.next()) { |
294 RelocInfo::Mode mode = it.rinfo()->rmode(); | 294 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 295 DCHECK(RelocInfo::IsCodeTarget(mode)); |
295 if (RelocInfo::IsCodeTarget(mode)) { | 296 if (RelocInfo::IsCodeTarget(mode)) { |
296 Code* target = | 297 Code* target = |
297 Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); | 298 Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); |
298 if (target->kind() == kind && | 299 if (target->kind() == kind && |
299 target->constant_pool_offset() >= kPlaceholderMarker) { | 300 target->constant_pool_offset() >= kPlaceholderMarker) { |
300 // Patch direct calls to placeholder code objects. | 301 // Patch direct calls to placeholder code objects. |
301 uint32_t index = target->constant_pool_offset() - kPlaceholderMarker; | 302 uint32_t index = target->constant_pool_offset() - kPlaceholderMarker; |
302 CHECK(index < code_targets.size()); | 303 CHECK(index < code_targets.size()); |
303 Handle<Code> new_target = code_targets[index]; | 304 Handle<Code> new_target = code_targets[index]; |
304 if (target != *new_target) { | 305 if (target != *new_target) { |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 if (memcmp(bytes->GetChars(), "\0asm", 4)) return false; | 1012 if (memcmp(bytes->GetChars(), "\0asm", 4)) return false; |
1012 | 1013 |
1013 // All checks passed. | 1014 // All checks passed. |
1014 return true; | 1015 return true; |
1015 } | 1016 } |
1016 | 1017 |
1017 SeqOneByteString* GetWasmBytes(JSObject* wasm) { | 1018 SeqOneByteString* GetWasmBytes(JSObject* wasm) { |
1018 return SeqOneByteString::cast(wasm->GetInternalField(kWasmModuleBytesString)); | 1019 return SeqOneByteString::cast(wasm->GetInternalField(kWasmModuleBytesString)); |
1019 } | 1020 } |
1020 | 1021 |
1021 WasmDebugInfo* GetDebugInfo(JSObject* wasm) { | 1022 WasmDebugInfo* GetDebugInfo(Handle<JSObject> wasm) { |
1022 Object* info = wasm->GetInternalField(kWasmDebugInfo); | 1023 Object* info = wasm->GetInternalField(kWasmDebugInfo); |
1023 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); | 1024 if (!info->IsUndefined(wasm->GetIsolate())) return WasmDebugInfo::cast(info); |
1024 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(handle(wasm)); | 1025 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(wasm); |
1025 wasm->SetInternalField(kWasmDebugInfo, *new_info); | 1026 wasm->SetInternalField(kWasmDebugInfo, *new_info); |
1026 return *new_info; | 1027 return *new_info; |
1027 } | 1028 } |
1028 | 1029 |
1029 int GetNumberOfFunctions(JSObject* wasm) { | 1030 int GetNumberOfFunctions(JSObject* wasm) { |
1030 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); | 1031 Object* func_names_obj = wasm->GetInternalField(kWasmFunctionNamesArray); |
1031 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. | 1032 // TODO(clemensh): this looks inside an array constructed elsewhere. Refactor. |
1032 return ByteArray::cast(func_names_obj)->get_int(0); | 1033 return ByteArray::cast(func_names_obj)->get_int(0); |
1033 } | 1034 } |
1034 | 1035 |
| 1036 JSArrayBuffer* GetWasmMemoryBuffer(JSObject* wasm) { |
| 1037 DCHECK(IsWasmObject(wasm)); |
| 1038 return JSArrayBuffer::cast(wasm->GetInternalField(kWasmMemArrayBuffer)); |
| 1039 } |
| 1040 |
| 1041 Code* GetWasmFunctionCode(JSObject* wasm, uint32_t func_index) { |
| 1042 FixedArray* code_table = |
| 1043 FixedArray::cast(wasm->GetInternalField(kWasmModuleCodeTable)); |
| 1044 DCHECK_LE(func_index, static_cast<unsigned>(kMaxInt)); |
| 1045 int func_index_int = static_cast<int>(func_index); |
| 1046 DCHECK_LE(func_index_int, code_table->length()); |
| 1047 return Code::cast(code_table->get(func_index_int)); |
| 1048 } |
| 1049 |
1035 namespace testing { | 1050 namespace testing { |
1036 | 1051 |
1037 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 1052 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
1038 const byte* module_end, bool asm_js) { | 1053 const byte* module_end, bool asm_js) { |
1039 HandleScope scope(isolate); | 1054 HandleScope scope(isolate); |
1040 Zone zone(isolate->allocator()); | 1055 Zone zone(isolate->allocator()); |
1041 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); | 1056 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); |
1042 | 1057 |
1043 // Decode the module, but don't verify function bodies, since we'll | 1058 // Decode the module, but don't verify function bodies, since we'll |
1044 // be compiling them anyway. | 1059 // be compiling them anyway. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 1113 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
1099 } | 1114 } |
1100 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 1115 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
1101 return -1; | 1116 return -1; |
1102 } | 1117 } |
1103 | 1118 |
1104 } // namespace testing | 1119 } // namespace testing |
1105 } // namespace wasm | 1120 } // namespace wasm |
1106 } // namespace internal | 1121 } // namespace internal |
1107 } // namespace v8 | 1122 } // namespace v8 |
OLD | NEW |