Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/compiler/wasm-compiler.h" | |
| 9 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| 10 #include "src/debug/debug.h" | 11 #include "src/debug/debug.h" |
| 11 #include "src/factory.h" | 12 #include "src/factory.h" |
| 12 #include "src/frames-inl.h" | 13 #include "src/frames-inl.h" |
| 13 #include "src/objects-inl.h" | 14 #include "src/objects-inl.h" |
| 14 #include "src/v8memory.h" | 15 #include "src/v8memory.h" |
| 15 #include "src/wasm/wasm-module.h" | 16 #include "src/wasm/wasm-module.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| 19 | 20 |
| 21 namespace { | |
| 22 const int kWasmMemArrayBuffer = 2; | |
| 23 } | |
| 24 | |
| 20 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { | 25 RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { |
| 21 HandleScope scope(isolate); | 26 HandleScope scope(isolate); |
| 22 DCHECK_EQ(1, args.length()); | 27 DCHECK_EQ(1, args.length()); |
| 23 uint32_t delta_pages = 0; | 28 uint32_t delta_pages = 0; |
| 24 CHECK(args[0]->ToUint32(&delta_pages)); | 29 CHECK(args[0]->ToUint32(&delta_pages)); |
| 25 Handle<JSObject> module_object; | 30 Handle<JSObject> module_object; |
| 26 | 31 |
| 27 { | 32 { |
| 28 // Get the module JSObject | 33 // Get the module JSObject |
| 29 DisallowHeapAllocation no_allocation; | 34 DisallowHeapAllocation no_allocation; |
| 30 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); | 35 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); |
| 31 Address pc = | 36 Address pc = |
| 32 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); | 37 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); |
| 33 Code* code = | 38 Code* code = |
| 34 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; | 39 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; |
| 35 FixedArray* deopt_data = code->deoptimization_data(); | 40 FixedArray* deopt_data = code->deoptimization_data(); |
| 36 DCHECK(deopt_data->length() == 2); | 41 DCHECK(deopt_data->length() == 2); |
| 37 module_object = Handle<JSObject>::cast(handle(deopt_data->get(0), isolate)); | 42 module_object = Handle<JSObject>::cast(handle(deopt_data->get(0), isolate)); |
| 38 CHECK(!module_object->IsNull(isolate)); | 43 CHECK(!module_object->IsNull(isolate)); |
| 39 } | 44 } |
| 40 | 45 |
| 41 Address old_mem_start, new_mem_start; | 46 Address old_mem_start, new_mem_start; |
| 42 uint32_t old_size, new_size; | 47 uint32_t old_size, new_size; |
| 43 const int kWasmMemArrayBuffer = 2; | |
| 44 | 48 |
| 45 // Get mem buffer associated with module object | 49 // Get mem buffer associated with module object |
| 46 Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer), | 50 Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer), |
| 47 isolate); | 51 isolate); |
| 48 | 52 |
| 49 if (obj->IsUndefined(isolate)) { | 53 if (obj->IsUndefined(isolate)) { |
| 50 // If module object does not have linear memory associated with it, | 54 // If module object does not have linear memory associated with it, |
| 51 // Allocate new array buffer of given size. | 55 // Allocate new array buffer of given size. |
| 52 old_mem_start = nullptr; | 56 old_mem_start = nullptr; |
| 53 old_size = 0; | 57 old_size = 0; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 // Set new buffer to be wasm memory | 107 // Set new buffer to be wasm memory |
| 104 module_object->SetInternalField(kWasmMemArrayBuffer, *buffer); | 108 module_object->SetInternalField(kWasmMemArrayBuffer, *buffer); |
| 105 | 109 |
| 106 CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start, | 110 CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start, |
| 107 new_mem_start, old_size, new_size)); | 111 new_mem_start, old_size, new_size)); |
| 108 | 112 |
| 109 return *isolate->factory()->NewNumberFromUint(old_size / | 113 return *isolate->factory()->NewNumberFromUint(old_size / |
| 110 wasm::WasmModule::kPageSize); | 114 wasm::WasmModule::kPageSize); |
| 111 } | 115 } |
| 112 | 116 |
| 117 RUNTIME_FUNCTION(Runtime_JITSingleFunction) { | |
| 118 const int fixed_args = 6; | |
|
titzer
2016/07/14 08:59:43
Most of this functionality should somehow be in sr
ritesht
2016/07/14 18:10:00
Acknowledged.
| |
| 119 | |
| 120 HandleScope scope(isolate); | |
| 121 DCHECK_LE(fixed_args, args.length()); | |
| 122 CONVERT_SMI_ARG_CHECKED(base, 0); | |
| 123 CONVERT_SMI_ARG_CHECKED(length, 1); | |
| 124 CONVERT_SMI_ARG_CHECKED(index, 2); | |
| 125 CONVERT_ARG_HANDLE_CHECKED(FixedArray, function_table, 3); | |
| 126 CONVERT_UINT32_ARG_CHECKED(sig_index, 4); | |
| 127 CONVERT_SMI_ARG_CHECKED(return_count, 5); | |
| 128 | |
| 129 Handle<JSObject> module_object; | |
| 130 | |
| 131 { | |
| 132 // Get the module JSObject | |
| 133 DisallowHeapAllocation no_allocation; | |
| 134 const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); | |
| 135 Address pc = | |
| 136 Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); | |
| 137 Code* code = | |
| 138 isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; | |
| 139 FixedArray* deopt_data = code->deoptimization_data(); | |
| 140 DCHECK(deopt_data->length() == 2); | |
| 141 module_object = Handle<JSObject>::cast(handle(deopt_data->get(0), isolate)); | |
| 142 CHECK(!module_object->IsNull(isolate)); | |
| 143 } | |
| 144 | |
| 145 // Get mem buffer associated with module object | |
| 146 Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer), | |
| 147 isolate); | |
| 148 | |
| 149 if (obj->IsUndefined(isolate)) { | |
| 150 return isolate->heap()->undefined_value(); | |
| 151 } | |
| 152 | |
| 153 Handle<JSArrayBuffer> mem_buffer = Handle<JSArrayBuffer>::cast(obj); | |
| 154 | |
| 155 wasm::WasmModule module(reinterpret_cast<byte*>(mem_buffer->backing_store())); | |
| 156 wasm::ErrorThrower thrower(isolate, "JITSingleFunction"); | |
| 157 wasm::ModuleEnv module_env; | |
| 158 module_env.module = &module; | |
| 159 module_env.instance = nullptr; | |
| 160 module_env.origin = wasm::kWasmOrigin; | |
| 161 | |
| 162 uint32_t signature_size = args.length() - fixed_args; | |
| 163 wasm::LocalType* sig_types = new wasm::LocalType[signature_size]; | |
| 164 | |
| 165 for (uint32_t i = 0; i < signature_size; ++i) { | |
| 166 CONVERT_SMI_ARG_CHECKED(sig_type, i + fixed_args); | |
| 167 sig_types[i] = static_cast<wasm::LocalType>(sig_type); | |
| 168 } | |
| 169 wasm::FunctionSig sig(return_count, signature_size - return_count, sig_types); | |
| 170 | |
| 171 wasm::WasmFunction func; | |
| 172 func.sig = &sig; | |
| 173 func.func_index = index; | |
| 174 func.sig_index = sig_index; | |
| 175 func.name_offset = 0; | |
| 176 func.name_length = 0; | |
| 177 func.code_start_offset = base; | |
| 178 func.code_end_offset = base + length; | |
| 179 | |
| 180 Handle<Code> code = compiler::WasmCompilationUnit::CompileWasmFunction( | |
| 181 &thrower, isolate, &module_env, &func); | |
| 182 | |
| 183 delete[] sig_types; | |
| 184 if (thrower.error()) { | |
| 185 return isolate->heap()->undefined_value(); | |
| 186 } | |
| 187 | |
| 188 function_table->set(index, Smi::FromInt(sig_index)); | |
| 189 function_table->set(index + function_table->length() / 2, *code); | |
| 190 | |
| 191 return isolate->heap()->undefined_value(); | |
| 192 } | |
| 113 } // namespace internal | 193 } // namespace internal |
| 114 } // namespace v8 | 194 } // namespace v8 |
| OLD | NEW |