deps: backport 2cd2f5feff3 from upstream v8

Original commit message:

    Remove experimental fast accessor builder API

    As the code isn't used, but would have to be ported from hand-written
    assembly to CodeStubAssembler anyways, I propose to remove it and
    restore it if we decide that we actually need it.

    R=vogelheim@chromium.org
    BUG=

    Change-Id: Iffd7fc6ec534b1dd7a9144da900424355c8a7a02
    Reviewed-on: https://chromium-review.googlesource.com/453461
    Commit-Queue: Jochen Eisinger <jochen@chromium.org>
    Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org>
    Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#43763}

Ref: https://github.com/v8/v8/commit/2cd2f5feff3

PR-URL: https://github.com/nodejs/node/pull/12875
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Jochen Eisinger authored and James M Snell committed 2017-05-28 07:00:32 -07:00
1 parent 19c0c07446
commit 9edd6d8ddb
37 files changed
+14 -2336

No files matched your search

-5
View File
@@ -887,7 +887,6 @@ v8_source_set("v8_base") {
### gcmole(all) ###
"include/v8-debug.h",
"include/v8-experimental.h",
"include/v8-platform.h",
"include/v8-profiler.h",
"include/v8-testing.h",
@@ -905,8 +904,6 @@ v8_source_set("v8_base") {
"src/api-arguments-inl.h",
"src/api-arguments.cc",
"src/api-arguments.h",
"src/api-experimental.cc",
"src/api-experimental.h",
"src/api-natives.cc",
"src/api-natives.h",
"src/api.cc",
@@ -1386,8 +1383,6 @@ v8_source_set("v8_base") {
"src/external-reference-table.h",
"src/factory.cc",
"src/factory.h",
"src/fast-accessor-assembler.cc",
"src/fast-accessor-assembler.h",
"src/fast-dtoa.cc",
"src/fast-dtoa.h",
"src/feedback-vector-inl.h",
-58
View File
@@ -1,58 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* This header contains a set of experimental V8 APIs. We hope these will
* become a part of standard V8, but they may also be removed if we deem the
* experiment to not be successul.
*/
#ifndef V8_INCLUDE_V8_EXPERIMENTAL_H_
#define V8_INCLUDE_V8_EXPERIMENTAL_H_
#include "v8.h" // NOLINT(build/include)
namespace v8 {
namespace experimental {
// Allow the embedder to construct accessors that V8 can compile and use
// directly, without jumping into the runtime.
class V8_EXPORT FastAccessorBuilder {
public:
struct ValueId {
size_t value_id;
};
struct LabelId {
size_t label_id;
};
static FastAccessorBuilder* New(Isolate* isolate);
ValueId IntegerConstant(int int_constant);
ValueId GetReceiver();
ValueId LoadInternalField(ValueId value_id, int field_no);
ValueId LoadInternalFieldUnchecked(ValueId value_id, int field_no);
ValueId LoadValue(ValueId value_id, int offset);
ValueId LoadObject(ValueId value_id, int offset);
ValueId ToSmi(ValueId value_id);
void ReturnValue(ValueId value_id);
void CheckFlagSetOrReturnNull(ValueId value_id, int mask);
void CheckNotZeroOrReturnNull(ValueId value_id);
LabelId MakeLabel();
void SetLabel(LabelId label_id);
void Goto(LabelId label_id);
void CheckNotZeroOrJump(ValueId value_id, LabelId label_id);
ValueId Call(v8::FunctionCallback callback, ValueId value_id);
private:
FastAccessorBuilder() = delete;
FastAccessorBuilder(const FastAccessorBuilder&) = delete;
~FastAccessorBuilder() = delete;
void operator=(const FastAccessorBuilder&) = delete;
};
} // namespace experimental
} // namespace v8
#endif // V8_INCLUDE_V8_EXPERIMENTAL_H_
+2 -17
View File
@@ -137,10 +137,6 @@ class CallHandlerHelper;
class EscapableHandleScope;
template<typename T> class ReturnValue;
namespace experimental {
class FastAccessorBuilder;
} // namespace experimental
namespace internal {
class Arguments;
class Heap;
@@ -5098,16 +5094,6 @@ class V8_EXPORT FunctionTemplate : public Template {
static MaybeLocal<FunctionTemplate> FromSnapshot(Isolate* isolate,
size_t index);
/**
* Creates a function template with a fast handler. If a fast handler is set,
* the callback cannot be null.
*/
static Local<FunctionTemplate> NewWithFastHandler(
Isolate* isolate, FunctionCallback callback,
experimental::FastAccessorBuilder* fast_handler = nullptr,
Local<Value> data = Local<Value>(),
Local<Signature> signature = Local<Signature>(), int length = 0);
/**
* Creates a function template backed/cached by a private property.
*/
@@ -5135,9 +5121,8 @@ class V8_EXPORT FunctionTemplate : public Template {
* callback is called whenever the function created from this
* FunctionTemplate is called.
*/
void SetCallHandler(
FunctionCallback callback, Local<Value> data = Local<Value>(),
experimental::FastAccessorBuilder* fast_handler = nullptr);
void SetCallHandler(FunctionCallback callback,
Local<Value> data = Local<Value>());
/** Set the predefined length property for the FunctionTemplate. */
void SetLength(int length);
-139
View File
@@ -1,139 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Implementation for v8-experimental.h.
*/
#include "src/api-experimental.h"
#include "include/v8-experimental.h"
#include "include/v8.h"
#include "src/api.h"
#include "src/fast-accessor-assembler.h"
#include "src/objects-inl.h"
namespace {
v8::internal::FastAccessorAssembler* FromApi(
v8::experimental::FastAccessorBuilder* builder) {
return reinterpret_cast<v8::internal::FastAccessorAssembler*>(builder);
}
v8::experimental::FastAccessorBuilder* FromInternal(
v8::internal::FastAccessorAssembler* fast_accessor_assembler) {
return reinterpret_cast<v8::experimental::FastAccessorBuilder*>(
fast_accessor_assembler);
}
} // namespace
namespace v8 {
namespace internal {
namespace experimental {
MaybeHandle<Code> BuildCodeFromFastAccessorBuilder(
v8::experimental::FastAccessorBuilder* fast_handler) {
i::MaybeHandle<i::Code> code;
if (fast_handler != nullptr) {
auto faa = FromApi(fast_handler);
code = faa->Build();
CHECK(!code.is_null());
delete faa;
}
return code;
}
} // namespace experimental
} // namespace internal
namespace experimental {
FastAccessorBuilder* FastAccessorBuilder::New(Isolate* isolate) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
internal::FastAccessorAssembler* faa =
new internal::FastAccessorAssembler(i_isolate);
return FromInternal(faa);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::IntegerConstant(
int const_value) {
return FromApi(this)->IntegerConstant(const_value);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::GetReceiver() {
return FromApi(this)->GetReceiver();
}
FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalField(
ValueId value, int field_no) {
return FromApi(this)->LoadInternalField(value, field_no);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::LoadInternalFieldUnchecked(
ValueId value, int field_no) {
return FromApi(this)->LoadInternalFieldUnchecked(value, field_no);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::LoadValue(ValueId value_id,
int offset) {
return FromApi(this)->LoadValue(value_id, offset);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::LoadObject(ValueId value_id,
int offset) {
return FromApi(this)->LoadObject(value_id, offset);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::ToSmi(ValueId value_id) {
return FromApi(this)->ToSmi(value_id);
}
void FastAccessorBuilder::ReturnValue(ValueId value) {
FromApi(this)->ReturnValue(value);
}
void FastAccessorBuilder::CheckFlagSetOrReturnNull(ValueId value_id, int mask) {
FromApi(this)->CheckFlagSetOrReturnNull(value_id, mask);
}
void FastAccessorBuilder::CheckNotZeroOrReturnNull(ValueId value_id) {
FromApi(this)->CheckNotZeroOrReturnNull(value_id);
}
FastAccessorBuilder::LabelId FastAccessorBuilder::MakeLabel() {
return FromApi(this)->MakeLabel();
}
void FastAccessorBuilder::SetLabel(LabelId label_id) {
FromApi(this)->SetLabel(label_id);
}
void FastAccessorBuilder::Goto(LabelId label_id) {
FromApi(this)->Goto(label_id);
}
void FastAccessorBuilder::CheckNotZeroOrJump(ValueId value_id,
LabelId label_id) {
FromApi(this)->CheckNotZeroOrJump(value_id, label_id);
}
FastAccessorBuilder::ValueId FastAccessorBuilder::Call(
v8::FunctionCallback callback, ValueId value_id) {
return FromApi(this)->Call(callback, value_id);
}
} // namespace experimental
} // namespace v8
-28
View File
@@ -1,28 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_API_EXPERIMENTAL_H_
#define V8_API_EXPERIMENTAL_H_
namespace v8 {
namespace internal {
class Code;
template <typename T>
class MaybeHandle;
} // internal;
namespace experimental {
class FastAccessorBuilder;
} // experimental
namespace internal {
namespace experimental {
v8::internal::MaybeHandle<v8::internal::Code> BuildCodeFromFastAccessorBuilder(
v8::experimental::FastAccessorBuilder* fast_handler);
} // namespace experimental
} // namespace internal
} // namespace v8
#endif // V8_API_EXPERIMENTAL_H_
+10 -31
View File
@@ -12,12 +12,10 @@
#include <limits>
#include <vector>
#include "include/v8-debug.h"
#include "include/v8-experimental.h"
#include "include/v8-profiler.h"
#include "include/v8-testing.h"
#include "include/v8-util.h"
#include "src/accessors.h"
#include "src/api-experimental.h"
#include "src/api-natives.h"
#include "src/assert-scope.h"
#include "src/background-parsing-task.h"
@@ -1286,8 +1284,7 @@ void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
}
static Local<FunctionTemplate> FunctionTemplateNew(
i::Isolate* isolate, FunctionCallback callback,
experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
v8::Local<Signature> signature, int length, bool do_not_cache,
v8::Local<Private> cached_property_name = v8::Local<Private>()) {
i::Handle<i::Struct> struct_obj =
@@ -1305,7 +1302,7 @@ static Local<FunctionTemplate> FunctionTemplateNew(
if (data.IsEmpty()) {
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler);
Utils::ToLocal(obj)->SetCallHandler(callback, data);
}
obj->set_length(length);
obj->set_undetectable(false);
@@ -1328,8 +1325,8 @@ Local<FunctionTemplate> FunctionTemplate::New(
// function templates when the isolate is created for serialization.
LOG_API(i_isolate, FunctionTemplate, New);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
auto templ = FunctionTemplateNew(i_isolate, callback, nullptr, data,
signature, length, false);
auto templ =
FunctionTemplateNew(i_isolate, callback, data, signature, length, false);
if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
return templ;
}
@@ -1349,25 +1346,14 @@ MaybeLocal<FunctionTemplate> FunctionTemplate::FromSnapshot(Isolate* isolate,
return Local<FunctionTemplate>();
}
Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler(
Isolate* isolate, FunctionCallback callback,
experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
v8::Local<Signature> signature, int length) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, FunctionTemplate, NewWithFastHandler);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature,
length, false);
}
Local<FunctionTemplate> FunctionTemplate::NewWithCache(
Isolate* isolate, FunctionCallback callback, Local<Private> cache_property,
Local<Value> data, Local<Signature> signature, int length) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, FunctionTemplate, NewWithCache);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature,
length, false, cache_property);
return FunctionTemplateNew(i_isolate, callback, data, signature, length,
false, cache_property);
}
Local<Signature> Signature::New(Isolate* isolate,
@@ -1387,10 +1373,8 @@ Local<AccessorSignature> AccessorSignature::New(
(obj)->setter(*foreign); \
} while (false)
void FunctionTemplate::SetCallHandler(
FunctionCallback callback, v8::Local<Value> data,
experimental::FastAccessorBuilder* fast_handler) {
void FunctionTemplate::SetCallHandler(FunctionCallback callback,
v8::Local<Value> data) {
auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
i::Isolate* isolate = info->GetIsolate();
@@ -1401,11 +1385,6 @@ void FunctionTemplate::SetCallHandler(
i::Handle<i::CallHandlerInfo> obj =
i::Handle<i::CallHandlerInfo>::cast(struct_obj);
SET_FIELD_WRAPPED(obj, set_callback, callback);
i::MaybeHandle<i::Code> code =
i::experimental::BuildCodeFromFastAccessorBuilder(fast_handler);
if (!code.is_null()) {
obj->set_fast_handler(*code.ToHandleChecked());
}
if (data.IsEmpty()) {
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
@@ -5081,8 +5060,8 @@ MaybeLocal<Function> Function::New(Local<Context> context,
i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
LOG_API(isolate, Function, New);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
auto templ = FunctionTemplateNew(isolate, callback, nullptr, data,
Local<Signature>(), length, true);
auto templ = FunctionTemplateNew(isolate, callback, data, Local<Signature>(),
length, true);
if (behavior == ConstructorBehavior::kThrow) templ->RemovePrototype();
return templ->GetFunction(context);
}
-98
View File
@@ -1710,104 +1710,6 @@ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
}
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Register scratch0, Register scratch1,
Register scratch2,
Label* receiver_check_failed) {
Register signature = scratch0;
Register map = scratch1;
Register constructor = scratch2;
// If there is no signature, return the holder.
__ ldr(signature, FieldMemOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
__ CompareRoot(signature, Heap::kUndefinedValueRootIndex);
Label receiver_check_passed;
__ b(eq, &receiver_check_passed);
// Walk the prototype chain.
__ ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(constructor, map, ip, ip);
__ cmp(ip, Operand(JS_FUNCTION_TYPE));
Label next_prototype;
__ b(ne, &next_prototype);
Register type = constructor;
__ ldr(type,
FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ ldr(type, FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ cmp(signature, type);
__ b(eq, &receiver_check_passed);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype);
__ CompareObjectType(type, ip, ip, FUNCTION_TEMPLATE_INFO_TYPE);
// Otherwise load the parent function template and iterate.
__ ldr(type,
FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset),
eq);
__ b(&function_template_loop, eq);
// Load the next prototype.
__ bind(&next_prototype);
__ ldr(ip, FieldMemOperand(map, Map::kBitField3Offset));
__ tst(ip, Operand(Map::HasHiddenPrototype::kMask));
__ b(eq, receiver_check_failed);
__ ldr(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
__ ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ b(&prototype_loop_start);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r0 : number of arguments excluding receiver
// -- r1 : callee
// -- lr : return address
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
// -- sp[4 * argc] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
__ ldr(r3, FieldMemOperand(r3, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ ldr(r2, MemOperand(sp, r0, LSL, kPointerSizeLog2));
CompatibleReceiverCheck(masm, r2, r3, r4, r5, r6, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ ldr(r4, FieldMemOperand(r3, FunctionTemplateInfo::kCallCodeOffset));
__ ldr(r4, FieldMemOperand(r4, CallHandlerInfo::kFastHandlerOffset));
__ add(r4, r4, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(r4);
// Compatible receiver check failed: throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
// Drop the arguments (including the receiver)
__ add(r0, r0, Operand(1));
__ add(sp, sp, Operand(r0, LSL, kPointerSizeLog2));
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-98
View File
@@ -1715,104 +1715,6 @@ void Builtins::Generate_NotifySoftDeoptimized(MacroAssembler* masm) {
Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::SOFT);
}
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Register scratch0, Register scratch1,
Register scratch2,
Label* receiver_check_failed) {
Register signature = scratch0;
Register map = scratch1;
Register constructor = scratch2;
// If there is no signature, return the holder.
__ Ldr(signature, FieldMemOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
__ CompareRoot(signature, Heap::kUndefinedValueRootIndex);
Label receiver_check_passed;
__ B(eq, &receiver_check_passed);
// Walk the prototype chain.
__ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ Bind(&prototype_loop_start);
// Get the constructor, if any
__ GetMapConstructor(constructor, map, x16, x16);
__ cmp(x16, Operand(JS_FUNCTION_TYPE));
Label next_prototype;
__ B(ne, &next_prototype);
Register type = constructor;
__ Ldr(type,
FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ Ldr(type, FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ Bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ Cmp(signature, type);
__ B(eq, &receiver_check_passed);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype);
__ CompareObjectType(type, x16, x17, FUNCTION_TEMPLATE_INFO_TYPE);
__ B(ne, &next_prototype);
// Otherwise load the parent function template and iterate.
__ Ldr(type,
FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
__ B(&function_template_loop);
// Load the next prototype.
__ Bind(&next_prototype);
__ Ldr(x16, FieldMemOperand(map, Map::kBitField3Offset));
__ Tst(x16, Operand(Map::HasHiddenPrototype::kMask));
__ B(eq, receiver_check_failed);
__ Ldr(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
__ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ B(&prototype_loop_start);
__ Bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- x0 : number of arguments excluding receiver
// -- x1 : callee
// -- lr : return address
// -- sp[0] : last argument
// -- ...
// -- sp[8 * (argc - 1)] : first argument
// -- sp[8 * argc] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ Ldr(x3, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
__ Ldr(x3, FieldMemOperand(x3, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ Ldr(x2, MemOperand(jssp, x0, LSL, kPointerSizeLog2));
CompatibleReceiverCheck(masm, x2, x3, x4, x5, x6, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ Ldr(x4, FieldMemOperand(x3, FunctionTemplateInfo::kCallCodeOffset));
__ Ldr(x4, FieldMemOperand(x4, CallHandlerInfo::kFastHandlerOffset));
__ Add(x4, x4, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(x4);
// Compatible receiver check failed: throw an Illegal Invocation exception.
__ Bind(&receiver_check_failed);
// Drop the arguments (including the receiver)
__ add(x0, x0, Operand(1));
__ Drop(x0);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-1
View File
@@ -182,7 +182,6 @@ class Isolate;
API(HandleApiCall) \
API(HandleApiCallAsFunction) \
API(HandleApiCallAsConstructor) \
ASM(HandleFastApiCall) \
\
/* Adapters for Turbofan into runtime */ \
ASM(AllocateInNewSpace) \
-106
View File
@@ -3240,112 +3240,6 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
}
}
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Register scratch0, Register scratch1,
Label* receiver_check_failed) {
// If there is no signature, return the holder.
__ CompareRoot(FieldOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset),
Heap::kUndefinedValueRootIndex);
Label receiver_check_passed;
__ j(equal, &receiver_check_passed, Label::kNear);
// Walk the prototype chain.
__ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(scratch0, scratch0, scratch1);
__ CmpInstanceType(scratch1, JS_FUNCTION_TYPE);
Label next_prototype;
__ j(not_equal, &next_prototype, Label::kNear);
// Get the constructor's signature.
__ mov(scratch0,
FieldOperand(scratch0, JSFunction::kSharedFunctionInfoOffset));
__ mov(scratch0,
FieldOperand(scratch0, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ cmp(scratch0, FieldOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
__ j(equal, &receiver_check_passed, Label::kNear);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(scratch0, &next_prototype, Label::kNear);
__ CmpObjectType(scratch0, FUNCTION_TEMPLATE_INFO_TYPE, scratch1);
__ j(not_equal, &next_prototype, Label::kNear);
// Otherwise load the parent function template and iterate.
__ mov(scratch0,
FieldOperand(scratch0, FunctionTemplateInfo::kParentTemplateOffset));
__ jmp(&function_template_loop, Label::kNear);
// Load the next prototype.
__ bind(&next_prototype);
__ mov(receiver, FieldOperand(receiver, HeapObject::kMapOffset));
__ test(FieldOperand(receiver, Map::kBitField3Offset),
Immediate(Map::HasHiddenPrototype::kMask));
__ j(zero, receiver_check_failed);
__ mov(receiver, FieldOperand(receiver, Map::kPrototypeOffset));
__ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ jmp(&prototype_loop_start, Label::kNear);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- eax : number of arguments (not including the receiver)
// -- edi : callee
// -- esi : context
// -- esp[0] : return address
// -- esp[4] : last argument
// -- ...
// -- esp[eax * 4] : first argument
// -- esp[(eax + 1) * 4] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ mov(ecx, Operand(esp, eax, times_pointer_size, kPCOnStackSize));
__ Push(eax);
CompatibleReceiverCheck(masm, ecx, ebx, edx, eax, &receiver_check_failed);
__ Pop(eax);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ mov(edx, FieldOperand(ebx, FunctionTemplateInfo::kCallCodeOffset));
__ mov(edx, FieldOperand(edx, CallHandlerInfo::kFastHandlerOffset));
__ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag));
__ jmp(edx);
// Compatible receiver check failed: pop return address, arguments and
// receiver and throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
__ Pop(eax);
__ PopReturnAddressTo(ebx);
__ lea(eax, Operand(eax, times_pointer_size, 1 * kPointerSize));
__ add(esp, eax);
__ PushReturnAddressFrom(ebx);
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-98
View File
@@ -1723,104 +1723,6 @@ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
}
// Clobbers {t2, t3, t4, t5}.
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Label* receiver_check_failed) {
Register signature = t2;
Register map = t3;
Register constructor = t4;
Register scratch = t5;
// If there is no signature, return the holder.
__ lw(signature, FieldMemOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
Label receiver_check_passed;
__ JumpIfRoot(signature, Heap::kUndefinedValueRootIndex,
&receiver_check_passed);
// Walk the prototype chain.
__ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(constructor, map, scratch, scratch);
Label next_prototype;
__ Branch(&next_prototype, ne, scratch, Operand(JS_FUNCTION_TYPE));
Register type = constructor;
__ lw(type,
FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ lw(type, FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ Branch(&receiver_check_passed, eq, signature, Operand(type),
USE_DELAY_SLOT);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype);
__ GetObjectType(type, scratch, scratch);
__ Branch(&next_prototype, ne, scratch, Operand(FUNCTION_TEMPLATE_INFO_TYPE));
// Otherwise load the parent function template and iterate.
__ lw(type,
FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
__ Branch(&function_template_loop);
// Load the next prototype and iterate.
__ bind(&next_prototype);
__ lw(scratch, FieldMemOperand(map, Map::kBitField3Offset));
__ DecodeField<Map::HasHiddenPrototype>(scratch);
__ Branch(receiver_check_failed, eq, scratch, Operand(zero_reg));
__ lw(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
__ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
__ Branch(&prototype_loop_start);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
// -- a1 : callee
// -- ra : return address
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
// -- sp[4 * argc] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ lw(t1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ lw(t1, FieldMemOperand(t1, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ Lsa(t8, sp, a0, kPointerSizeLog2);
__ lw(t0, MemOperand(t8));
CompatibleReceiverCheck(masm, t0, t1, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ lw(t2, FieldMemOperand(t1, FunctionTemplateInfo::kCallCodeOffset));
__ lw(t2, FieldMemOperand(t2, CallHandlerInfo::kFastHandlerOffset));
__ Addu(t2, t2, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(t2);
// Compatible receiver check failed: throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
// Drop the arguments (including the receiver);
__ Addu(t8, t8, Operand(kPointerSize));
__ addu(sp, t8, zero_reg);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-99
View File
@@ -1714,105 +1714,6 @@ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
}
// Clobbers {t2, t3, a4, a5}.
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Label* receiver_check_failed) {
Register signature = t2;
Register map = t3;
Register constructor = a4;
Register scratch = a5;
// If there is no signature, return the holder.
__ ld(signature, FieldMemOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
Label receiver_check_passed;
__ JumpIfRoot(signature, Heap::kUndefinedValueRootIndex,
&receiver_check_passed);
// Walk the prototype chain.
__ ld(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(constructor, map, scratch, scratch);
Label next_prototype;
__ Branch(&next_prototype, ne, scratch, Operand(JS_FUNCTION_TYPE));
Register type = constructor;
__ ld(type,
FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ ld(type, FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ Branch(&receiver_check_passed, eq, signature, Operand(type),
USE_DELAY_SLOT);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype);
__ GetObjectType(type, scratch, scratch);
__ Branch(&next_prototype, ne, scratch, Operand(FUNCTION_TEMPLATE_INFO_TYPE));
// Otherwise load the parent function template and iterate.
__ ld(type,
FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
__ Branch(&function_template_loop);
// Load the next prototype.
__ bind(&next_prototype);
__ lwu(scratch, FieldMemOperand(map, Map::kBitField3Offset));
__ DecodeField<Map::HasHiddenPrototype>(scratch);
__ Branch(receiver_check_failed, eq, scratch, Operand(zero_reg));
__ ld(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
__ ld(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ Branch(&prototype_loop_start);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- a0 : number of arguments excluding receiver
// -- a1 : callee
// -- ra : return address
// -- sp[0] : last argument
// -- ...
// -- sp[8 * (argc - 1)] : first argument
// -- sp[8 * argc] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ ld(t1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
__ ld(t1, FieldMemOperand(t1, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check
Label receiver_check_failed;
__ Dlsa(t8, sp, a0, kPointerSizeLog2);
__ ld(t0, MemOperand(t8));
CompatibleReceiverCheck(masm, t0, t1, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ ld(t2, FieldMemOperand(t1, FunctionTemplateInfo::kCallCodeOffset));
__ ld(t2, FieldMemOperand(t2, CallHandlerInfo::kFastHandlerOffset));
__ Daddu(t2, t2, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Jump(t2);
// Compatible receiver check failed: throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
// Drop the arguments (including the receiver);
__ Daddu(t8, t8, Operand(kPointerSize));
__ daddu(sp, t8, zero_reg);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-101
View File
@@ -1734,107 +1734,6 @@ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
}
// Clobbers registers {r7, r8, r9, r10}.
void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Label* receiver_check_failed) {
Register signature = r7;
Register map = r8;
Register constructor = r9;
Register scratch = r10;
// If there is no signature, return the holder.
__ LoadP(signature, FieldMemOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
Label receiver_check_passed;
__ JumpIfRoot(signature, Heap::kUndefinedValueRootIndex,
&receiver_check_passed);
// Walk the prototype chain.
__ LoadP(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(constructor, map, scratch, scratch);
__ cmpi(scratch, Operand(JS_FUNCTION_TYPE));
Label next_prototype;
__ bne(&next_prototype);
Register type = constructor;
__ LoadP(type,
FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ LoadP(type,
FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ cmp(signature, type);
__ beq(&receiver_check_passed);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype);
__ CompareObjectType(type, scratch, scratch, FUNCTION_TEMPLATE_INFO_TYPE);
__ bne(&next_prototype);
// Otherwise load the parent function template and iterate.
__ LoadP(type,
FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
__ b(&function_template_loop);
// Load the next prototype.
__ bind(&next_prototype);
__ lwz(scratch, FieldMemOperand(map, Map::kBitField3Offset));
__ DecodeField<Map::HasHiddenPrototype>(scratch, SetRC);
__ beq(receiver_check_failed, cr0);
__ LoadP(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
__ LoadP(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ b(&prototype_loop_start);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r3 : number of arguments excluding receiver
// -- r4 : callee
// -- lr : return address
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
// -- sp[4 * argc] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ LoadP(r6, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
__ LoadP(r6, FieldMemOperand(r6, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ ShiftLeftImm(r11, r3, Operand(kPointerSizeLog2));
__ LoadPX(r5, MemOperand(sp, r11));
CompatibleReceiverCheck(masm, r5, r6, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ LoadP(r7, FieldMemOperand(r6, FunctionTemplateInfo::kCallCodeOffset));
__ LoadP(r7, FieldMemOperand(r7, CallHandlerInfo::kFastHandlerOffset));
__ addi(ip, r7, Operand(Code::kHeaderSize - kHeapObjectTag));
__ JumpToJSEntry(ip);
// Compatible receiver check failed: throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
// Drop the arguments (including the receiver);
__ addi(r11, r11, Operand(kPointerSize));
__ add(sp, sp, r11);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-101
View File
@@ -1743,107 +1743,6 @@ void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
}
// Clobbers registers {r6, r7, r8, r9}.
void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Label* receiver_check_failed) {
Register signature = r6;
Register map = r7;
Register constructor = r8;
Register scratch = r9;
// If there is no signature, return the holder.
__ LoadP(signature, FieldMemOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
Label receiver_check_passed;
__ JumpIfRoot(signature, Heap::kUndefinedValueRootIndex,
&receiver_check_passed);
// Walk the prototype chain.
__ LoadP(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(constructor, map, scratch, scratch);
__ CmpP(scratch, Operand(JS_FUNCTION_TYPE));
Label next_prototype;
__ bne(&next_prototype);
Register type = constructor;
__ LoadP(type,
FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ LoadP(type,
FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ CmpP(signature, type);
__ beq(&receiver_check_passed);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype);
__ CompareObjectType(type, scratch, scratch, FUNCTION_TEMPLATE_INFO_TYPE);
__ bne(&next_prototype);
// Otherwise load the parent function template and iterate.
__ LoadP(type,
FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
__ b(&function_template_loop);
// Load the next prototype.
__ bind(&next_prototype);
__ LoadlW(scratch, FieldMemOperand(map, Map::kBitField3Offset));
__ DecodeField<Map::HasHiddenPrototype>(scratch);
__ beq(receiver_check_failed);
__ LoadP(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
__ LoadP(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ b(&prototype_loop_start);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r2 : number of arguments excluding receiver
// -- r3 : callee
// -- lr : return address
// -- sp[0] : last argument
// -- ...
// -- sp[4 * (argc - 1)] : first argument
// -- sp[4 * argc] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ LoadP(r5, FieldMemOperand(r3, JSFunction::kSharedFunctionInfoOffset));
__ LoadP(r5, FieldMemOperand(r5, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ ShiftLeftP(r1, r2, Operand(kPointerSizeLog2));
__ LoadP(r4, MemOperand(sp, r1));
CompatibleReceiverCheck(masm, r4, r5, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ LoadP(r6, FieldMemOperand(r5, FunctionTemplateInfo::kCallCodeOffset));
__ LoadP(r6, FieldMemOperand(r6, CallHandlerInfo::kFastHandlerOffset));
__ AddP(ip, r6, Operand(Code::kHeaderSize - kHeapObjectTag));
__ JumpToJSEntry(ip);
// Compatible receiver check failed: throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
// Drop the arguments (including the receiver);
__ AddP(r1, r1, Operand(kPointerSize));
__ AddP(sp, sp, r1);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-108
View File
@@ -3132,114 +3132,6 @@ void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
__ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
}
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Register scratch0, Register scratch1,
Register scratch2,
Label* receiver_check_failed) {
Register signature = scratch0;
Register map = scratch1;
Register constructor = scratch2;
// If there is no signature, return the holder.
__ movp(signature, FieldOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
__ CompareRoot(signature, Heap::kUndefinedValueRootIndex);
Label receiver_check_passed;
__ j(equal, &receiver_check_passed, Label::kNear);
// Walk the prototype chain.
__ movp(map, FieldOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(constructor, map, kScratchRegister);
__ CmpInstanceType(kScratchRegister, JS_FUNCTION_TYPE);
Label next_prototype;
__ j(not_equal, &next_prototype, Label::kNear);
// Get the constructor's signature.
Register type = constructor;
__ movp(type,
FieldOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
__ movp(type, FieldOperand(type, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ cmpp(signature, type);
__ j(equal, &receiver_check_passed, Label::kNear);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(type, &next_prototype, Label::kNear);
__ CmpObjectType(type, FUNCTION_TEMPLATE_INFO_TYPE, kScratchRegister);
__ j(not_equal, &next_prototype, Label::kNear);
// Otherwise load the parent function template and iterate.
__ movp(type,
FieldOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
__ jmp(&function_template_loop, Label::kNear);
// Load the next prototype.
__ bind(&next_prototype);
__ testq(FieldOperand(map, Map::kBitField3Offset),
Immediate(Map::HasHiddenPrototype::kMask));
__ j(zero, receiver_check_failed);
__ movp(receiver, FieldOperand(map, Map::kPrototypeOffset));
__ movp(map, FieldOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ jmp(&prototype_loop_start, Label::kNear);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- rax : number of arguments (not including the receiver)
// -- rdi : callee
// -- rsi : context
// -- rsp[0] : return address
// -- rsp[8] : last argument
// -- ...
// -- rsp[rax * 8] : first argument
// -- rsp[(rax + 1) * 8] : receiver
// -----------------------------------
StackArgumentsAccessor args(rsp, rax);
// Load the FunctionTemplateInfo.
__ movp(rbx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
__ movp(rbx, FieldOperand(rbx, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ movp(rcx, args.GetReceiverOperand());
CompatibleReceiverCheck(masm, rcx, rbx, rdx, r8, r9, &receiver_check_failed);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ movp(rdx, FieldOperand(rbx, FunctionTemplateInfo::kCallCodeOffset));
__ movp(rdx, FieldOperand(rdx, CallHandlerInfo::kFastHandlerOffset));
__ addp(rdx, Immediate(Code::kHeaderSize - kHeapObjectTag));
__ jmp(rdx);
// Compatible receiver check failed: pop return address, arguments and
// receiver and throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
__ PopReturnAddressTo(rbx);
__ leap(rax, Operand(rax, times_pointer_size, 1 * kPointerSize));
__ addp(rsp, rax);
__ PushReturnAddressFrom(rbx);
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-106
View File
@@ -3175,112 +3175,6 @@ void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
}
}
static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
Register function_template_info,
Register scratch0, Register scratch1,
Label* receiver_check_failed) {
// If there is no signature, return the holder.
__ CompareRoot(FieldOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset),
Heap::kUndefinedValueRootIndex);
Label receiver_check_passed;
__ j(equal, &receiver_check_passed, Label::kNear);
// Walk the prototype chain.
__ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
Label prototype_loop_start;
__ bind(&prototype_loop_start);
// Get the constructor, if any.
__ GetMapConstructor(scratch0, scratch0, scratch1);
__ CmpInstanceType(scratch1, JS_FUNCTION_TYPE);
Label next_prototype;
__ j(not_equal, &next_prototype, Label::kNear);
// Get the constructor's signature.
__ mov(scratch0,
FieldOperand(scratch0, JSFunction::kSharedFunctionInfoOffset));
__ mov(scratch0,
FieldOperand(scratch0, SharedFunctionInfo::kFunctionDataOffset));
// Loop through the chain of inheriting function templates.
Label function_template_loop;
__ bind(&function_template_loop);
// If the signatures match, we have a compatible receiver.
__ cmp(scratch0, FieldOperand(function_template_info,
FunctionTemplateInfo::kSignatureOffset));
__ j(equal, &receiver_check_passed, Label::kNear);
// If the current type is not a FunctionTemplateInfo, load the next prototype
// in the chain.
__ JumpIfSmi(scratch0, &next_prototype, Label::kNear);
__ CmpObjectType(scratch0, FUNCTION_TEMPLATE_INFO_TYPE, scratch1);
__ j(not_equal, &next_prototype, Label::kNear);
// Otherwise load the parent function template and iterate.
__ mov(scratch0,
FieldOperand(scratch0, FunctionTemplateInfo::kParentTemplateOffset));
__ jmp(&function_template_loop, Label::kNear);
// Load the next prototype.
__ bind(&next_prototype);
__ mov(receiver, FieldOperand(receiver, HeapObject::kMapOffset));
__ test(FieldOperand(receiver, Map::kBitField3Offset),
Immediate(Map::HasHiddenPrototype::kMask));
__ j(zero, receiver_check_failed);
__ mov(receiver, FieldOperand(receiver, Map::kPrototypeOffset));
__ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
// Iterate.
__ jmp(&prototype_loop_start, Label::kNear);
__ bind(&receiver_check_passed);
}
void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- eax : number of arguments (not including the receiver)
// -- edi : callee
// -- esi : context
// -- esp[0] : return address
// -- esp[4] : last argument
// -- ...
// -- esp[eax * 4] : first argument
// -- esp[(eax + 1) * 4] : receiver
// -----------------------------------
// Load the FunctionTemplateInfo.
__ mov(ebx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
__ mov(ebx, FieldOperand(ebx, SharedFunctionInfo::kFunctionDataOffset));
// Do the compatible receiver check.
Label receiver_check_failed;
__ mov(ecx, Operand(esp, eax, times_pointer_size, kPCOnStackSize));
__ Push(eax);
CompatibleReceiverCheck(masm, ecx, ebx, edx, eax, &receiver_check_failed);
__ Pop(eax);
// Get the callback offset from the FunctionTemplateInfo, and jump to the
// beginning of the code.
__ mov(edx, FieldOperand(ebx, FunctionTemplateInfo::kCallCodeOffset));
__ mov(edx, FieldOperand(edx, CallHandlerInfo::kFastHandlerOffset));
__ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag));
__ jmp(edx);
// Compatible receiver check failed: pop return address, arguments and
// receiver and throw an Illegal Invocation exception.
__ bind(&receiver_check_failed);
__ Pop(eax);
__ PopReturnAddressTo(ebx);
__ lea(eax, Operand(eax, times_pointer_size, 1 * kPointerSize));
__ add(esp, eax);
__ PushReturnAddressFrom(ebx);
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ TailCallRuntime(Runtime::kThrowIllegalInvocation);
}
}
static void Generate_OnStackReplacementHelper(MacroAssembler* masm,
bool has_handler_frame) {
// Lookup the function in the JavaScript frame.
-3
View File
@@ -372,9 +372,6 @@ bool AccessInfoFactory::ComputePropertyAccessInfo(
if (!optimization.is_simple_api_call()) {
return false;
}
if (optimization.api_call_info()->fast_handler()->IsCode()) {
return false;
}
if (V8_UNLIKELY(FLAG_runtime_stats)) return false;
}
if (access_mode == AccessMode::kLoad) {
-270
View File
@@ -1,270 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/fast-accessor-assembler.h"
#include "src/base/logging.h"
#include "src/code-stub-assembler.h"
#include "src/code-stubs.h" // For CallApiCallbackStub.
#include "src/handles-inl.h"
#include "src/objects-inl.h"
#include "src/objects.h" // For FAA::LoadInternalField impl.
namespace v8 {
namespace internal {
using compiler::Node;
using compiler::CodeAssemblerLabel;
using compiler::CodeAssemblerVariable;
FastAccessorAssembler::FastAccessorAssembler(Isolate* isolate)
: zone_(isolate->allocator(), ZONE_NAME),
isolate_(isolate),
assembler_state_(new compiler::CodeAssemblerState(
isolate, zone(), 1, Code::ComputeFlags(Code::STUB),
"FastAccessorAssembler")),
assembler_(new CodeStubAssembler(assembler_state_.get())),
state_(kBuilding) {}
FastAccessorAssembler::~FastAccessorAssembler() { Clear(); }
FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant(
int const_value) {
CHECK_EQ(kBuilding, state_);
return FromRaw(assembler_->NumberConstant(const_value));
}
FastAccessorAssembler::ValueId FastAccessorAssembler::GetReceiver() {
CHECK_EQ(kBuilding, state_);
// For JS functions, the receiver is parameter 0.
return FromRaw(assembler_->Parameter(0));
}
FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField(
ValueId value_id, int field_no) {
CHECK_EQ(kBuilding, state_);
CodeAssemblerVariable result(assembler_.get(),
MachineRepresentation::kTagged);
LabelId is_not_jsobject = MakeLabel();
CodeAssemblerLabel merge(assembler_.get(), &result);
CheckIsJSObjectOrJump(value_id, is_not_jsobject);
Node* internal_field = assembler_->LoadObjectField(
FromId(value_id), JSObject::kHeaderSize + kPointerSize * field_no);
result.Bind(internal_field);
assembler_->Goto(&merge);
// Return null, mimicking the C++ counterpart.
SetLabel(is_not_jsobject);
result.Bind(assembler_->NullConstant());
assembler_->Goto(&merge);
// Return.
assembler_->Bind(&merge);
return FromRaw(result.value());
}
FastAccessorAssembler::ValueId
FastAccessorAssembler::LoadInternalFieldUnchecked(ValueId value_id,
int field_no) {
CHECK_EQ(kBuilding, state_);
// Defensive debug checks.
if (FLAG_debug_code) {
LabelId is_jsobject = MakeLabel();
LabelId is_not_jsobject = MakeLabel();
CheckIsJSObjectOrJump(value_id, is_not_jsobject);
assembler_->Goto(FromId(is_jsobject));
SetLabel(is_not_jsobject);
assembler_->DebugBreak();
assembler_->Goto(FromId(is_jsobject));
SetLabel(is_jsobject);
}
Node* result = assembler_->LoadObjectField(
FromId(value_id), JSObject::kHeaderSize + kPointerSize * field_no);
return FromRaw(result);
}
FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue(
ValueId value_id, int offset) {
CHECK_EQ(kBuilding, state_);
return FromRaw(assembler_->LoadBufferObject(FromId(value_id), offset,
MachineType::IntPtr()));
}
FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(
ValueId value_id, int offset) {
CHECK_EQ(kBuilding, state_);
return FromRaw(assembler_->LoadBufferObject(
assembler_->LoadBufferObject(FromId(value_id), offset), 0,
MachineType::AnyTagged()));
}
FastAccessorAssembler::ValueId FastAccessorAssembler::ToSmi(ValueId value_id) {
CHECK_EQ(kBuilding, state_);
return FromRaw(assembler_->SmiTag(FromId(value_id)));
}
void FastAccessorAssembler::ReturnValue(ValueId value_id) {
CHECK_EQ(kBuilding, state_);
assembler_->Return(FromId(value_id));
}
void FastAccessorAssembler::CheckFlagSetOrReturnNull(ValueId value_id,
int mask) {
CHECK_EQ(kBuilding, state_);
CodeAssemblerLabel pass(assembler_.get());
CodeAssemblerLabel fail(assembler_.get());
Node* value = FromId(value_id);
assembler_->Branch(
assembler_->IsSetWord(assembler_->BitcastTaggedToWord(value), mask),
&pass, &fail);
assembler_->Bind(&fail);
assembler_->Return(assembler_->NullConstant());
assembler_->Bind(&pass);
}
void FastAccessorAssembler::CheckNotZeroOrReturnNull(ValueId value_id) {
CHECK_EQ(kBuilding, state_);
CodeAssemblerLabel is_null(assembler_.get());
CodeAssemblerLabel not_null(assembler_.get());
assembler_->Branch(
assembler_->WordEqual(FromId(value_id), assembler_->SmiConstant(0)),
&is_null, &not_null);
assembler_->Bind(&is_null);
assembler_->Return(assembler_->NullConstant());
assembler_->Bind(&not_null);
}
FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() {
CHECK_EQ(kBuilding, state_);
return FromRaw(new CodeAssemblerLabel(assembler_.get()));
}
void FastAccessorAssembler::SetLabel(LabelId label_id) {
CHECK_EQ(kBuilding, state_);
assembler_->Bind(FromId(label_id));
}
void FastAccessorAssembler::Goto(LabelId label_id) {
CHECK_EQ(kBuilding, state_);
assembler_->Goto(FromId(label_id));
}
void FastAccessorAssembler::CheckNotZeroOrJump(ValueId value_id,
LabelId label_id) {
CHECK_EQ(kBuilding, state_);
CodeAssemblerLabel pass(assembler_.get());
assembler_->Branch(
assembler_->WordEqual(FromId(value_id), assembler_->SmiConstant(0)),
FromId(label_id), &pass);
assembler_->Bind(&pass);
}
FastAccessorAssembler::ValueId FastAccessorAssembler::Call(
FunctionCallback callback_function, ValueId arg) {
CHECK_EQ(kBuilding, state_);
// Wrap the FunctionCallback in an ExternalReference.
ApiFunction callback_api_function(FUNCTION_ADDR(callback_function));
ExternalReference callback(&callback_api_function,
ExternalReference::DIRECT_API_CALL, isolate());
// Create & call API callback via stub.
const int kJSParameterCount = 1;
CallApiCallbackStub stub(isolate(), kJSParameterCount, true, true);
CallInterfaceDescriptor descriptor = stub.GetCallInterfaceDescriptor();
DCHECK_EQ(4, descriptor.GetParameterCount());
DCHECK_EQ(0, descriptor.GetStackParameterCount());
Node* context = assembler_->GetJSContextParameter();
Node* target = assembler_->HeapConstant(stub.GetCode());
Node* call = assembler_->CallStub(
descriptor, target, context,
assembler_->UndefinedConstant(), // callee (there's no JSFunction)
assembler_->UndefinedConstant(), // call_data (undefined)
assembler_->Parameter(0), // receiver (same as holder in this case)
assembler_->ExternalConstant(callback), // API callback function
FromId(arg)); // JS argument, on stack
return FromRaw(call);
}
void FastAccessorAssembler::CheckIsJSObjectOrJump(ValueId value_id,
LabelId label_id) {
CHECK_EQ(kBuilding, state_);
// Determine the 'value' object's instance type.
Node* instance_type = assembler_->LoadInstanceType(FromId(value_id));
CodeAssemblerLabel is_jsobject(assembler_.get());
// Check whether we have a proper JSObject.
assembler_->GotoIf(
assembler_->Word32Equal(
instance_type, assembler_->Int32Constant(Internals::kJSObjectType)),
&is_jsobject);
// JSApiObject?.
assembler_->GotoIfNot(
assembler_->Word32Equal(instance_type, assembler_->Int32Constant(
Internals::kJSApiObjectType)),
FromId(label_id));
// Continue.
assembler_->Goto(&is_jsobject);
assembler_->Bind(&is_jsobject);
}
MaybeHandle<Code> FastAccessorAssembler::Build() {
CHECK_EQ(kBuilding, state_);
Handle<Code> code =
compiler::CodeAssembler::GenerateCode(assembler_state_.get());
state_ = !code.is_null() ? kBuilt : kError;
Clear();
return code;
}
FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) {
nodes_.push_back(node);
ValueId value_id = {nodes_.size() - 1};
return value_id;
}
FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw(
CodeAssemblerLabel* label) {
labels_.push_back(label);
LabelId label_id = {labels_.size() - 1};
return label_id;
}
Node* FastAccessorAssembler::FromId(ValueId value) const {
CHECK_LT(value.value_id, nodes_.size());
CHECK_NOT_NULL(nodes_.at(value.value_id));
return nodes_.at(value.value_id);
}
CodeAssemblerLabel* FastAccessorAssembler::FromId(LabelId label) const {
CHECK_LT(label.label_id, labels_.size());
CHECK_NOT_NULL(labels_.at(label.label_id));
return labels_.at(label.label_id);
}
void FastAccessorAssembler::Clear() {
for (auto label : labels_) {
delete label;
}
nodes_.clear();
labels_.clear();
}
} // namespace internal
} // namespace v8
-122
View File
@@ -1,122 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_FAST_ACCESSOR_ASSEMBLER_H_
#define V8_FAST_ACCESSOR_ASSEMBLER_H_
#include <stdint.h>
#include <memory>
#include <vector>
#include "include/v8-experimental.h"
#include "src/base/macros.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
class Code;
class CodeStubAssembler;
class Isolate;
template <typename T>
class MaybeHandle;
namespace compiler {
class Node;
class CodeAssemblerLabel;
class CodeAssemblerState;
class CodeAssemblerVariable;
}
// This interface "exports" an aggregated subset of RawMachineAssembler, for
// use by the API to implement Fast Dom Accessors.
//
// This interface is made for this single purpose only and does not attempt
// to implement a general purpose solution. If you need one, please look at
// RawMachineAssembler instead.
//
// The life cycle of a FastAccessorAssembler has two phases:
// - After creating the instance, you can call an arbitrary sequence of
// builder functions to build the desired function.
// - When done, you can Build() the accessor and query for the build results.
//
// You cannot call any result getters before Build() was called & successful;
// and you cannot call any builder functions after Build() was called.
class FastAccessorAssembler {
public:
typedef v8::experimental::FastAccessorBuilder::ValueId ValueId;
typedef v8::experimental::FastAccessorBuilder::LabelId LabelId;
typedef v8::FunctionCallback FunctionCallback;
explicit FastAccessorAssembler(Isolate* isolate);
~FastAccessorAssembler();
// Builder / assembler functions:
ValueId IntegerConstant(int int_constant);
ValueId GetReceiver();
ValueId LoadInternalField(ValueId value_id, int field_no);
// Loads internal field and assumes the object is indeed a valid API object
// with the proper internal fields present.
// The intended use is to call this on an object whose structure has already
// been checked previously, e.g. the accessor's receiver, which is map-checked
// before the fast accessor is called on it. Using this on an arbitrary object
// will result in unsafe memory accesses.
ValueId LoadInternalFieldUnchecked(ValueId value_id, int field_no);
ValueId LoadValue(ValueId value_id, int offset);
ValueId LoadObject(ValueId value_id, int offset);
// Converts a machine integer to a SMI.
ValueId ToSmi(ValueId value_id);
// Builder / assembler functions for control flow.
void ReturnValue(ValueId value_id);
void CheckFlagSetOrReturnNull(ValueId value_id, int mask);
void CheckNotZeroOrReturnNull(ValueId value_id);
LabelId MakeLabel();
void SetLabel(LabelId label_id);
void Goto(LabelId label_id);
void CheckNotZeroOrJump(ValueId value_id, LabelId label_id);
// C++ callback.
ValueId Call(FunctionCallback callback, ValueId arg);
// Assemble the code.
MaybeHandle<Code> Build();
private:
ValueId FromRaw(compiler::Node* node);
LabelId FromRaw(compiler::CodeAssemblerLabel* label);
compiler::Node* FromId(ValueId value) const;
compiler::CodeAssemblerLabel* FromId(LabelId value) const;
void CheckIsJSObjectOrJump(ValueId value, LabelId label_id);
void Clear();
Zone* zone() { return &zone_; }
Isolate* isolate() const { return isolate_; }
Zone zone_;
Isolate* isolate_;
std::unique_ptr<compiler::CodeAssemblerState> assembler_state_;
std::unique_ptr<CodeStubAssembler> assembler_;
// To prevent exposing the RMA internals to the outside world, we'll map
// Node + Label pointers integers wrapped in ValueId and LabelId instances.
// These vectors maintain this mapping.
std::vector<compiler::Node*> nodes_;
std::vector<compiler::CodeAssemblerLabel*> labels_;
// Remember the current state for easy error checking. (We prefer to be
// strict as this class will be exposed at the API.)
enum { kBuilding, kBuilt, kError } state_;
DISALLOW_COPY_AND_ASSIGN(FastAccessorAssembler);
};
} // namespace internal
} // namespace v8
#endif // V8_FAST_ACCESSOR_ASSEMBLER_H_
-7
View File
@@ -288,13 +288,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ ldr(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
ApiFunction fun(function_address);
-7
View File
@@ -190,13 +190,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ Ldr(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
ApiFunction fun(function_address);
-6
View File
@@ -201,12 +201,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ mov(data, FieldOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the code.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
__ mov(api_function_address, Immediate(function_address));
-6
View File
@@ -276,12 +276,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ lw(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
ApiFunction fun(function_address);
-6
View File
@@ -276,12 +276,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ ld(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
ApiFunction fun(function_address);
-7
View File
@@ -282,13 +282,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ LoadP(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
ApiFunction fun(function_address);
-7
View File
@@ -272,13 +272,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ LoadP(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
ApiFunction fun(function_address);
-7
View File
@@ -176,13 +176,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ movp(data, FieldOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the fast handler if present.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
__ Move(api_function_address, function_address,
-6
View File
@@ -201,12 +201,6 @@ void PropertyHandlerCompiler::GenerateApiAccessorCall(
__ mov(data, FieldOperand(data, CallHandlerInfo::kDataOffset));
}
if (api_call_info->fast_handler()->IsCode()) {
// Just tail call into the code.
__ Jump(handle(Code::cast(api_call_info->fast_handler())),
RelocInfo::CODE_TARGET);
return;
}
// Put api_function_address in place.
Address function_address = v8::ToCData<Address>(api_call_info->callback());
__ mov(api_function_address, Immediate(function_address));
-1
View File
@@ -5694,7 +5694,6 @@ BOOL_ACCESSORS(InterceptorInfo, flags, non_masking, kNonMasking)
ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset)
ACCESSORS(CallHandlerInfo, data, Object, kDataOffset)
ACCESSORS(CallHandlerInfo, fast_handler, Object, kFastHandlerOffset)
ACCESSORS(TemplateInfo, tag, Object, kTagOffset)
ACCESSORS(TemplateInfo, serial_number, Object, kSerialNumberOffset)
+1 -7
View File
@@ -1190,13 +1190,7 @@ Handle<SharedFunctionInfo> FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(
Handle<String> name = class_name->IsString()
? Handle<String>::cast(class_name)
: isolate->factory()->empty_string();
Handle<Code> code;
if (info->call_code()->IsCallHandlerInfo() &&
CallHandlerInfo::cast(info->call_code())->fast_handler()->IsCode()) {
code = isolate->builtins()->HandleFastApiCall();
} else {
code = isolate->builtins()->HandleApiCall();
}
Handle<Code> code = isolate->builtins()->HandleApiCall();
bool is_constructor = !info->remove_prototype();
Handle<SharedFunctionInfo> result =
isolate->factory()->NewSharedFunctionInfo(name, code, is_constructor);
+1 -3
View File
@@ -11173,7 +11173,6 @@ class CallHandlerInfo: public Struct {
public:
DECL_ACCESSORS(callback, Object)
DECL_ACCESSORS(data, Object)
DECL_ACCESSORS(fast_handler, Object)
DECLARE_CAST(CallHandlerInfo)
@@ -11183,8 +11182,7 @@ class CallHandlerInfo: public Struct {
static const int kCallbackOffset = HeapObject::kHeaderSize;
static const int kDataOffset = kCallbackOffset + kPointerSize;
static const int kFastHandlerOffset = kDataOffset + kPointerSize;
static const int kSize = kFastHandlerOffset + kPointerSize;
static const int kSize = kDataOffset + kPointerSize;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
-5
View File
@@ -392,7 +392,6 @@
}],
'sources': [ ### gcmole(all) ###
'../include/v8-debug.h',
'../include/v8-experimental.h',
'../include/v8-platform.h',
'../include/v8-profiler.h',
'../include/v8-testing.h',
@@ -409,8 +408,6 @@
'allocation.h',
'allocation-site-scopes.cc',
'allocation-site-scopes.h',
'api-experimental.cc',
'api-experimental.h',
'api.cc',
'api.h',
'api-arguments-inl.h',
@@ -893,8 +890,6 @@
'external-reference-table.h',
'factory.cc',
'factory.h',
'fast-accessor-assembler.cc',
'fast-accessor-assembler.h',
'fast-dtoa.cc',
'fast-dtoa.h',
'feedback-vector-inl.h',
-2
View File
@@ -104,7 +104,6 @@ v8_executable("cctest") {
"test-accessor-assembler.cc",
"test-accessors.cc",
"test-api-accessors.cc",
"test-api-fast-accessor-builder.cc",
"test-api-interceptors.cc",
"test-api.cc",
"test-api.h",
@@ -159,7 +158,6 @@ v8_executable("cctest") {
"test-platform.cc",
"test-profile-generator.cc",
"test-random-number-generator.cc",
"test-receiver-check-hidden-prototype.cc",
"test-regexp.cc",
"test-representation.cc",
"test-sampler-api.cc",
-2
View File
@@ -128,7 +128,6 @@
'test-api.h',
'test-api-accessors.cc',
'test-api-interceptors.cc',
'test-api-fast-accessor-builder.cc',
'test-array-list.cc',
'test-ast.cc',
'test-atomicops.cc',
@@ -179,7 +178,6 @@
'test-platform.cc',
'test-profile-generator.cc',
'test-random-number-generator.cc',
'test-receiver-check-hidden-prototype.cc',
'test-regexp.cc',
'test-representation.cc',
'test-sampler-api.cc',
-103
View File
@@ -4,115 +4,12 @@
#include "test/cctest/cctest.h"
#include "include/v8-experimental.h"
#include "include/v8.h"
#include "src/api.h"
#include "src/objects-inl.h"
namespace i = v8::internal;
static void CppAccessor42(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(42);
}
static void CppAccessor41(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(41);
}
v8::experimental::FastAccessorBuilder* FastAccessor(v8::Isolate* isolate) {
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
builder->ReturnValue(builder->IntegerConstant(41));
return builder;
}
TEST(FastAccessors) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
LocalContext env;
// We emulate Embedder-created DOM Node instances. Specifically:
// - 'parent': FunctionTemplate ~= DOM Node superclass
// - 'child': FunctionTemplate ~= a specific DOM node type, like a <div />
//
// We'll install both a C++-based and a JS-based accessor on the parent,
// and expect it to be callable on the child.
// Setup the parent template ( =~ DOM Node w/ accessors).
v8::Local<v8::FunctionTemplate> parent = v8::FunctionTemplate::New(isolate);
{
auto signature = v8::Signature::New(isolate, parent);
// cpp accessor as "firstChild":
parent->PrototypeTemplate()->SetAccessorProperty(
v8_str("firstChild"),
v8::FunctionTemplate::New(isolate, CppAccessor42,
v8::Local<v8::Value>(), signature));
// JS accessor as "firstChildRaw":
parent->PrototypeTemplate()->SetAccessorProperty(
v8_str("firstChildRaw"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, CppAccessor41, FastAccessor(isolate),
v8::Local<v8::Value>(), signature));
}
// Setup child object ( =~ a specific DOM Node, e.g. a <div> ).
// Also, make a creation function on the global object, so we can access it
// in a test.
v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate);
child->Inherit(parent);
CHECK(env->Global()
->Set(env.local(), v8_str("Node"),
child->GetFunction(env.local()).ToLocalChecked())
.IsJust());
// Setup done: Let's test it:
// The simple case: Run it once.
ExpectInt32("var n = new Node(); n.firstChild", 42);
ExpectInt32("var n = new Node(); n.firstChildRaw", 41);
// Run them in a loop. This will likely trigger the optimizing compiler:
ExpectInt32(
"var m = new Node(); "
"var sum = 0; "
"for (var i = 0; i < 10; ++i) { "
" sum += m.firstChild; "
" sum += m.firstChildRaw; "
"}; "
"sum;",
10 * (42 + 41));
// Obtain the accessor and call it via apply on the Node:
ExpectInt32(
"var n = new Node(); "
"var g = Object.getOwnPropertyDescriptor("
" n.__proto__.__proto__, 'firstChild')['get']; "
"g.apply(n);",
42);
ExpectInt32(
"var n = new Node(); "
"var g = Object.getOwnPropertyDescriptor("
" n.__proto__.__proto__, 'firstChildRaw')['get']; "
"g.apply(n);",
41);
ExpectInt32(
"var n = new Node();"
"var g = Object.getOwnPropertyDescriptor("
" n.__proto__.__proto__, 'firstChildRaw')['get'];"
"try {"
" var f = { firstChildRaw: '51' };"
" g.apply(f);"
"} catch(e) {"
" 31415;"
"}",
31415);
}
// The goal is to avoid the callback.
static void UnreachableCallback(
const v8::FunctionCallbackInfo<v8::Value>& info) {
-492
View File
@@ -1,492 +0,0 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdlib.h>
#include "include/v8.h"
#include "include/v8-experimental.h"
#include "src/api.h"
#include "src/objects-inl.h"
#include "test/cctest/cctest.h"
namespace {
// These tests mean to exercise v8::FastAccessorBuilder. Since initially the
// "native" accessor will get called, we need to "warmup" any accessor first,
// to make sure we're actually testing the v8::FastAccessorBuilder result.
// To accomplish this, we will
// - call each accesssor N times before the actual test.
// - wrap that call in a function, so that all such calls will go
// through a single call site.
// - bloat that function with a very long comment to prevent its inlining.
// - register a native accessor which is different from the build one
// (so that our tests will always fail if we don't end up in the 'fast'
// accessor).
//
// FN_WARMUP(name, src) define a JS function "name" with body "src".
// It adds the INLINE_SPOILER to prevent inlining and will call name()
// repeatedly to guarantee it's "warm".
//
// Use:
// CompileRun(FN_WARMUP("fn", "return something();"));
// ExpectXXX("fn(1234)", 5678);
#define INLINE_SPOILER \
" /* " \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
"*/ " // 16 lines * 64 'X' =~ 1024 character comment.
#define FN(name, src) "function " name "() { " src INLINE_SPOILER " }"
#define WARMUP(name, count) "for(i = 0; i < " count "; i++) { " name "() } "
#define FN_WARMUP(name, src) FN(name, src) "; " WARMUP(name, "2")
static void NativePropertyAccessor(
const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(v8_num(123));
}
const char* kWatermarkProperty = "watermark";
} // anonymous namespace
void CheckImplicitParameters(const v8::FunctionCallbackInfo<v8::Value>& info) {
v8::Isolate* isolate = info.GetIsolate();
CHECK_NOT_NULL(isolate);
auto context = isolate->GetCurrentContext();
CHECK(!context.IsEmpty());
// The context must point to the same isolate, this should be enough to
// validate the context, mainly to prevent having a random object instead.
CHECK_EQ(isolate, context->GetIsolate());
CHECK(info.Data()->IsUndefined());
CHECK(info.Holder()->Has(context, v8_str(kWatermarkProperty)).FromJust());
}
// Build a simple "fast accessor" and verify that it is being called.
TEST(FastAccessor) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate);
// Native accessor, bar, returns 123.
foo->PrototypeTemplate()->SetAccessorProperty(
v8_str("bar"),
v8::FunctionTemplate::New(isolate, NativePropertyAccessor));
// Fast accessor, barf, returns 124.
auto fab = v8::experimental::FastAccessorBuilder::New(isolate);
fab->ReturnValue(fab->IntegerConstant(124));
foo->PrototypeTemplate()->SetAccessorProperty(
v8_str("barf"), v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, fab));
// Install foo on the global object.
CHECK(env->Global()
->Set(env.local(), v8_str("foo"),
foo->GetFunction(env.local()).ToLocalChecked())
.FromJust());
// Wrap f.barf + IC warmup.
CompileRun(FN_WARMUP("barf", "f = new foo(); return f.barf"));
ExpectInt32("f = new foo(); f.bar", 123);
ExpectInt32("f = new foo(); f.barf", 123); // First call in this call site.
ExpectInt32("barf()", 124); // Call via warmed-up callsite.
}
void AddInternalFieldAccessor(v8::Isolate* isolate,
v8::Local<v8::Template> templ, const char* name,
int field_no, bool useUncheckedLoader) {
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
if (useUncheckedLoader) {
builder->ReturnValue(
builder->LoadInternalFieldUnchecked(builder->GetReceiver(), field_no));
} else {
builder->ReturnValue(
builder->LoadInternalField(builder->GetReceiver(), field_no));
}
templ->SetAccessorProperty(v8_str(name),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
void checkLoadInternalField(bool useUncheckedLoader, bool emitDebugChecks) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
// De/activate debug checks.
v8::internal::FLAG_debug_code = emitDebugChecks;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(3);
AddInternalFieldAccessor(isolate, foo, "field0", 0, useUncheckedLoader);
AddInternalFieldAccessor(isolate, foo, "field1", 1, useUncheckedLoader);
AddInternalFieldAccessor(isolate, foo, "field2", 2, useUncheckedLoader);
// Create an instance w/ 3 internal fields, put in a string, a Smi, nothing.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
obj->SetInternalField(0, v8_str("Hi there!"));
obj->SetInternalField(1, v8::Integer::New(isolate, 4321));
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Warmup.
CompileRun(FN_WARMUP("field0", "return obj.field0"));
CompileRun(FN_WARMUP("field1", "return obj.field1"));
CompileRun(FN_WARMUP("field2", "return obj.field2"));
// Access fields.
ExpectString("field0()", "Hi there!");
ExpectInt32("field1()", 4321);
ExpectUndefined("field2()");
}
// "Fast" accessor that accesses an internal field.
TEST(FastAccessorWithInternalField) { checkLoadInternalField(false, false); }
// "Fast" accessor that accesses an internal field using the fast(er)
// implementation of LoadInternalField.
TEST(FastAccessorLoadInternalFieldUnchecked) {
checkLoadInternalField(true, false);
checkLoadInternalField(true, true);
}
// "Fast" accessor with control flow via ...OrReturnNull methods.
TEST(FastAccessorOrReturnNull) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(2);
{
// accessor "nullcheck": Return null if field 0 is non-null object; else 5.
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
auto val = builder->LoadInternalField(builder->GetReceiver(), 0);
builder->CheckNotZeroOrReturnNull(val);
builder->ReturnValue(builder->IntegerConstant(5));
foo->SetAccessorProperty(v8_str("nullcheck"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
{
// accessor "maskcheck": Return null if field 1 has 3rd bit set.
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
auto val = builder->LoadInternalField(builder->GetReceiver(), 1);
builder->CheckFlagSetOrReturnNull(val, 0x4);
builder->ReturnValue(builder->IntegerConstant(42));
foo->SetAccessorProperty(v8_str("maskcheck"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// CheckNotZeroOrReturnNull:
CompileRun(FN_WARMUP("nullcheck", "return obj.nullcheck"));
obj->SetAlignedPointerInInternalField(0, /* anything != nullptr */ isolate);
ExpectInt32("nullcheck()", 5);
obj->SetAlignedPointerInInternalField(0, nullptr);
ExpectNull("nullcheck()");
// CheckFlagSetOrReturnNull:
CompileRun(FN_WARMUP("maskcheck", "return obj.maskcheck"));
obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xf0));
ExpectNull("maskcheck()");
obj->SetAlignedPointerInInternalField(1, reinterpret_cast<void*>(0xfe));
ExpectInt32("maskcheck()", 42);
}
// "Fast" accessor with simple control flow via explicit labels.
TEST(FastAccessorControlFlowWithLabels) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(1);
{
// accessor isnull: 0 for nullptr, else 1.
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
auto label = builder->MakeLabel();
auto val = builder->LoadInternalField(builder->GetReceiver(), 0);
builder->CheckNotZeroOrJump(val, label);
builder->ReturnValue(builder->IntegerConstant(1));
builder->SetLabel(label);
builder->ReturnValue(builder->IntegerConstant(0));
foo->SetAccessorProperty(v8_str("isnull"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// CheckNotZeroOrReturnNull:
CompileRun(FN_WARMUP("isnull", "return obj.isnull"));
obj->SetAlignedPointerInInternalField(0, /* anything != nullptr */ isolate);
ExpectInt32("isnull()", 1);
obj->SetAlignedPointerInInternalField(0, nullptr);
ExpectInt32("isnull()", 0);
}
// "Fast" accessor, loading things.
TEST(FastAccessorLoad) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(1);
// Internal field 0 is a pointer to a C++ data structure that we wish to load
// field values from.
struct {
size_t intval;
v8::Local<v8::String> v8val;
} val = {54321, v8_str("Hello")};
{
// accessor intisnonzero
int intval_offset =
static_cast<int>(reinterpret_cast<intptr_t>(&val.intval) -
reinterpret_cast<intptr_t>(&val));
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
auto label = builder->MakeLabel();
auto val = builder->LoadValue(
builder->LoadInternalField(builder->GetReceiver(), 0), intval_offset);
builder->CheckNotZeroOrJump(val, label);
builder->ReturnValue(builder->IntegerConstant(1));
builder->SetLabel(label);
builder->ReturnValue(builder->IntegerConstant(0));
foo->SetAccessorProperty(v8_str("nonzero"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
{
// accessor loadval
int v8val_offset = static_cast<int>(reinterpret_cast<intptr_t>(&val.v8val) -
reinterpret_cast<intptr_t>(&val));
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
builder->ReturnValue(builder->LoadObject(
builder->LoadInternalField(builder->GetReceiver(), 0), v8val_offset));
foo->SetAccessorProperty(v8_str("loadval"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
obj->SetAlignedPointerInInternalField(0, &val);
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Access val.intval:
CompileRun(FN_WARMUP("nonzero", "return obj.nonzero"));
ExpectInt32("nonzero()", 1);
val.intval = 0;
ExpectInt32("nonzero()", 0);
val.intval = 27;
ExpectInt32("nonzero()", 1);
// Access val.v8val:
CompileRun(FN_WARMUP("loadval", "return obj.loadval"));
ExpectString("loadval()", "Hello");
}
void ApiCallbackInt(const v8::FunctionCallbackInfo<v8::Value>& info) {
CheckImplicitParameters(info);
info.GetReturnValue().Set(12345);
}
const char* kApiCallbackStringValue =
"Hello World! Bizarro C++ world, actually.";
void ApiCallbackString(const v8::FunctionCallbackInfo<v8::Value>& info) {
CheckImplicitParameters(info);
info.GetReturnValue().Set(v8_str(kApiCallbackStringValue));
}
void ApiCallbackParam(const v8::FunctionCallbackInfo<v8::Value>& info) {
CheckImplicitParameters(info);
CHECK_EQ(1, info.Length());
CHECK(info[0]->IsNumber());
info.GetReturnValue().Set(info[0]);
}
// "Fast" accessor, callback to embedder
TEST(FastAccessorCallback) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
{
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
builder->ReturnValue(
builder->Call(&ApiCallbackInt, builder->IntegerConstant(999)));
foo->SetAccessorProperty(v8_str("int"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
builder = v8::experimental::FastAccessorBuilder::New(isolate);
builder->ReturnValue(
builder->Call(&ApiCallbackString, builder->IntegerConstant(0)));
foo->SetAccessorProperty(v8_str("str"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
builder = v8::experimental::FastAccessorBuilder::New(isolate);
builder->ReturnValue(
builder->Call(&ApiCallbackParam, builder->IntegerConstant(1000)));
foo->SetAccessorProperty(v8_str("param"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Add dummy property to validate the holder.
foo->Set(isolate, kWatermarkProperty, v8::Undefined(isolate));
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Callbacks:
CompileRun(FN_WARMUP("callbackint", "return obj.int"));
ExpectInt32("callbackint()", 12345);
CompileRun(FN_WARMUP("callbackstr", "return obj.str"));
ExpectString("callbackstr()", kApiCallbackStringValue);
CompileRun(FN_WARMUP("callbackparam", "return obj.param"));
ExpectInt32("callbackparam()", 1000);
}
TEST(FastAccessorToSmi) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(1);
{
// Accessor load_smi.
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
// Read the variable and convert it to a Smi.
auto flags = builder->LoadValue(
builder->LoadInternalField(builder->GetReceiver(), 0), 0);
builder->ReturnValue(builder->ToSmi(flags));
foo->SetAccessorProperty(v8_str("load_smi"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
uintptr_t flags;
obj->SetAlignedPointerInInternalField(0, &flags);
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Access flags.
CompileRun(FN_WARMUP("load_smi", "return obj.load_smi"));
flags = 54321;
ExpectInt32("load_smi()", 54321);
flags = 0;
ExpectInt32("load_smi()", 0);
flags = 123456789;
ExpectInt32("load_smi()", 123456789);
}
TEST(FastAccessorGoto) {
// Crankshaft support for fast accessors is not implemented; crankshafted
// code uses the slow accessor which breaks this test's expectations.
v8::internal::FLAG_always_opt = false;
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
v8::Local<v8::ObjectTemplate> foo = v8::ObjectTemplate::New(isolate);
foo->SetInternalFieldCount(1);
{
auto builder = v8::experimental::FastAccessorBuilder::New(isolate);
auto successLabel = builder->MakeLabel();
auto failLabel = builder->MakeLabel();
// The underlying raw assembler is clever enough to reject unreachable
// basic blocks, this instruction has no effect besides marking the failed
// return BB as reachable.
builder->CheckNotZeroOrJump(builder->IntegerConstant(1234), failLabel);
builder->Goto(successLabel);
builder->SetLabel(failLabel);
builder->ReturnValue(builder->IntegerConstant(0));
builder->SetLabel(successLabel);
builder->ReturnValue(builder->IntegerConstant(60707357));
foo->SetAccessorProperty(v8_str("goto_test"),
v8::FunctionTemplate::NewWithFastHandler(
isolate, NativePropertyAccessor, builder));
}
// Create an instance.
v8::Local<v8::Object> obj = foo->NewInstance(env.local()).ToLocalChecked();
CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
// Access flags.
CompileRun(FN_WARMUP("test", "return obj.goto_test"));
ExpectInt32("test()", 60707357);
}
@@ -1,73 +0,0 @@
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdlib.h>
#include "include/v8-experimental.h"
#include "src/v8.h"
#include "test/cctest/cctest.h"
namespace {
static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(41);
}
TEST(CompatibleReceiverBuiltin) {
// Check that the HandleFastApiCall builtin visits the hidden prototypes
// during the compatible receiver check.
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> current_context = isolate->GetCurrentContext();
v8::Local<v8::FunctionTemplate> constructor_template =
v8::FunctionTemplate::New(isolate);
v8::Local<v8::FunctionTemplate> prototype_template =
v8::FunctionTemplate::New(isolate);
prototype_template->SetHiddenPrototype(true);
v8::Local<v8::ObjectTemplate> proto_instance_template =
prototype_template->InstanceTemplate();
v8::experimental::FastAccessorBuilder* fast_accessor_builder =
v8::experimental::FastAccessorBuilder::New(isolate);
fast_accessor_builder->ReturnValue(
fast_accessor_builder->IntegerConstant(42));
v8::Local<v8::FunctionTemplate> accessor_template =
v8::FunctionTemplate::NewWithFastHandler(
isolate, SlowCallback, fast_accessor_builder, v8::Local<v8::Value>(),
v8::Signature::New(isolate, prototype_template));
proto_instance_template->SetAccessorProperty(
v8_str("bar"), accessor_template, v8::Local<v8::FunctionTemplate>(),
v8::ReadOnly);
v8::Local<v8::Object> object =
constructor_template->GetFunction(current_context)
.ToLocalChecked()
->NewInstance(current_context)
.ToLocalChecked();
v8::Local<v8::Object> hidden_prototype =
prototype_template->GetFunction(current_context)
.ToLocalChecked()
->NewInstance(current_context)
.ToLocalChecked();
CHECK(object->SetPrototype(current_context, hidden_prototype).FromJust());
context->Global()
->Set(current_context, v8_str("object"), object)
.FromMaybe(false);
CHECK_EQ(42, CompileRun("var getter = object.__lookupGetter__('bar');"
"getter.call(object)")
->Int32Value(current_context)
.FromJust());
}
} // namespace