Index: src/runtime/runtime-wasm.cc |
diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc |
index ff99e242e14610ad28dd029047568f1e358576c8..c883fb7e1a94fee7c4c064a8e1e64bd4e270e6bd 100644 |
--- a/src/runtime/runtime-wasm.cc |
+++ b/src/runtime/runtime-wasm.cc |
@@ -6,6 +6,7 @@ |
#include "src/arguments.h" |
#include "src/assembler.h" |
+#include "src/compiler/wasm-compiler.h" |
#include "src/conversions.h" |
#include "src/debug/debug.h" |
#include "src/factory.h" |
@@ -17,6 +18,10 @@ |
namespace v8 { |
namespace internal { |
+namespace { |
+const int kWasmMemArrayBuffer = 2; |
+} |
+ |
RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { |
HandleScope scope(isolate); |
DCHECK_EQ(1, args.length()); |
@@ -40,7 +45,6 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { |
Address old_mem_start, new_mem_start; |
uint32_t old_size, new_size; |
- const int kWasmMemArrayBuffer = 2; |
// Get mem buffer associated with module object |
Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer), |
@@ -110,5 +114,81 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { |
wasm::WasmModule::kPageSize); |
} |
+RUNTIME_FUNCTION(Runtime_JITSingleFunction) { |
+ 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.
|
+ |
+ HandleScope scope(isolate); |
+ DCHECK_LE(fixed_args, args.length()); |
+ CONVERT_SMI_ARG_CHECKED(base, 0); |
+ CONVERT_SMI_ARG_CHECKED(length, 1); |
+ CONVERT_SMI_ARG_CHECKED(index, 2); |
+ CONVERT_ARG_HANDLE_CHECKED(FixedArray, function_table, 3); |
+ CONVERT_UINT32_ARG_CHECKED(sig_index, 4); |
+ CONVERT_SMI_ARG_CHECKED(return_count, 5); |
+ |
+ Handle<JSObject> module_object; |
+ |
+ { |
+ // Get the module JSObject |
+ DisallowHeapAllocation no_allocation; |
+ const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); |
+ Address pc = |
+ Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); |
+ Code* code = |
+ isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; |
+ FixedArray* deopt_data = code->deoptimization_data(); |
+ DCHECK(deopt_data->length() == 2); |
+ module_object = Handle<JSObject>::cast(handle(deopt_data->get(0), isolate)); |
+ CHECK(!module_object->IsNull(isolate)); |
+ } |
+ |
+ // Get mem buffer associated with module object |
+ Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer), |
+ isolate); |
+ |
+ if (obj->IsUndefined(isolate)) { |
+ return isolate->heap()->undefined_value(); |
+ } |
+ |
+ Handle<JSArrayBuffer> mem_buffer = Handle<JSArrayBuffer>::cast(obj); |
+ |
+ wasm::WasmModule module(reinterpret_cast<byte*>(mem_buffer->backing_store())); |
+ wasm::ErrorThrower thrower(isolate, "JITSingleFunction"); |
+ wasm::ModuleEnv module_env; |
+ module_env.module = &module; |
+ module_env.instance = nullptr; |
+ module_env.origin = wasm::kWasmOrigin; |
+ |
+ uint32_t signature_size = args.length() - fixed_args; |
+ wasm::LocalType* sig_types = new wasm::LocalType[signature_size]; |
+ |
+ for (uint32_t i = 0; i < signature_size; ++i) { |
+ CONVERT_SMI_ARG_CHECKED(sig_type, i + fixed_args); |
+ sig_types[i] = static_cast<wasm::LocalType>(sig_type); |
+ } |
+ wasm::FunctionSig sig(return_count, signature_size - return_count, sig_types); |
+ |
+ wasm::WasmFunction func; |
+ func.sig = &sig; |
+ func.func_index = index; |
+ func.sig_index = sig_index; |
+ func.name_offset = 0; |
+ func.name_length = 0; |
+ func.code_start_offset = base; |
+ func.code_end_offset = base + length; |
+ |
+ Handle<Code> code = compiler::WasmCompilationUnit::CompileWasmFunction( |
+ &thrower, isolate, &module_env, &func); |
+ |
+ delete[] sig_types; |
+ if (thrower.error()) { |
+ return isolate->heap()->undefined_value(); |
+ } |
+ |
+ function_table->set(index, Smi::FromInt(sig_index)); |
+ function_table->set(index + function_table->length() / 2, *code); |
+ |
+ return isolate->heap()->undefined_value(); |
+} |
} // namespace internal |
} // namespace v8 |