X64: Create test JS-function and call it.
authorlrn@chromium.org <lrn@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Jun 2009 13:17:46 +0000 (13:17 +0000)
committerlrn@chromium.org <lrn@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Jun 2009 13:17:46 +0000 (13:17 +0000)
Review URL: http://codereview.chromium.org/123017

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2145 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/x64/assembler-x64-inl.h
src/x64/assembler-x64.cc
src/x64/codegen-x64.cc
src/x64/macro-assembler-x64.cc

index 6427649ef168696443b38ea7333c63053df4f6f1..397b02341c25d03adc181385ebc18c5fcf09d0fe 100644 (file)
@@ -251,7 +251,7 @@ Object** RelocInfo::call_object_address() {
 
 void Operand::set_modrm(int mod, Register rm) {
   ASSERT((mod & -4) == 0);
-  buf_[0] = mod << 6 | (rm.code() & 0x7);
+  buf_[0] = (mod << 6) | (rm.code() & 0x7);
   // Set REX.B to the high bit of rm.code().
   rex_ |= (rm.code() >> 3);
 }
index d7e8d68388bc3ea4f45fc90cc146ef76a471c6ad..556ba867d3a2be9fbdf3ac39fe57eb2352702d34 100644 (file)
@@ -81,7 +81,7 @@ Operand::Operand(Register base, int32_t disp): rex_(0) {
   }
 
   if (disp == 0 && !base.is(rbp) && !base.is(r13)) {
-    set_modrm(0, rsp);
+    set_modrm(0, base);
   } else if (is_int8(disp)) {
     set_modrm(1, base);
     set_disp8(disp);
index 06bc9d7a440747f47a2d2e2197b14dafb2fe09a1..ad186068afe471d9ab3ebbc68defb63d682f564c 100644 (file)
@@ -571,7 +571,8 @@ void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
     ExternalReference entry(Builtins::JSEntryTrampoline);
     __ load_rax(entry);
   }
-  __ call(FieldOperand(rax, Code::kHeaderSize));
+  __ lea(kScratchRegister, FieldOperand(rax, Code::kHeaderSize));
+  __ call(kScratchRegister);
 
   // Unlink this frame from the handler chain.
   __ movq(kScratchRegister, ExternalReference(Top::k_handler_address));
index b4caa3783da258a6e90adda929c04b79160a6d2a..cb68f3a549e7606a435be36bdfc61bd3dfed6dbd 100644 (file)
@@ -63,14 +63,38 @@ void MacroAssembler::ConstructAndTestJSFunction() {
   const int initial_buffer_size = 4 * KB;
   char* buffer = new char[initial_buffer_size];
   MacroAssembler masm(buffer, initial_buffer_size);
+
+  const uint64_t secret = V8_INT64_C(0xdeadbeefcafebabe);
 #define __ ACCESS_MASM((&masm))
   // Construct a simple JSfunction here, using Assembler and MacroAssembler
   // commands.
-  __ int3();
+  __ movq(rax, secret, RelocInfo::NONE);
+  __ ret(0);
 #undef __
   CodeDesc desc;
   masm.GetCode(&desc);
-  // TODO(X64): Create the function object and call it.
+  Code::Flags flags = Code::ComputeFlags(Code::FUNCTION);
+  Object* code = Heap::CreateCode(desc, NULL, flags, Handle<Object>::null());
+  if (!code->IsFailure()) {
+    Handle<Code> code_handle(Code::cast(code));
+    Handle<String> name =
+        Factory::NewStringFromAscii(Vector<const char>("foo", 3), NOT_TENURED);
+    Handle<JSFunction> function =
+        Factory::NewFunction(name,
+                             JS_FUNCTION_TYPE,
+                             JSObject::kHeaderSize,
+                             code_handle,
+                             true);
+    bool pending_exceptions;
+    Handle<Object> result =
+        Execution::Call(function,
+                        Handle<Object>::cast(function),
+                        0,
+                        NULL,
+                        &pending_exceptions);
+    CHECK(result->IsSmi());
+    CHECK(secret == reinterpret_cast<uint64_t>(*result));
+  }
 }