Commit a326691c authored by svenpanne's avatar svenpanne Committed by Commit bot

JavaScript stubs have access to their calling convention and minor key now.

First steps only, the TurboFan compilation is still triggered from C++ land.

Includes some simplifications/cleanups, too.

Review URL: https://codereview.chromium.org/1150263002

Cr-Commit-Position: refs/heads/master@{#28581}
parent eeb2d17b
......@@ -477,17 +477,31 @@ Handle<JSFunction> GetFunction(Isolate* isolate, const char* name) {
Handle<JSFunction> function = Handle<JSFunction>::cast(fun.ToHandleChecked());
DCHECK(!function->IsUndefined() &&
"JavaScript implementation of stub not found");
// Just to make sure nobody calls this...
function->set_code(isolate->builtins()->builtin(Builtins::kIllegal));
return function;
}
} // namespace
Handle<Code> TurboFanCodeStub::GenerateCode() {
// Get the outer ("stub generator") function.
const char* name = CodeStub::MajorName(MajorKey(), false);
Handle<JSFunction> outer = GetFunction(isolate(), name);
DCHECK_EQ(2, outer->shared()->length());
// Invoke the outer function to get the stub itself.
Factory* factory = isolate()->factory();
Handle<Object> call_conv = factory->InternalizeUtf8String(name);
Handle<Object> minor_key = factory->NewNumber(MinorKey());
Handle<Object> args[] = {call_conv, minor_key};
MaybeHandle<Object> result = Execution::Call(
isolate(), outer, factory->undefined_value(), 2, args, false);
Handle<JSFunction> inner = Handle<JSFunction>::cast(result.ToHandleChecked());
// Just to make sure nobody calls this...
inner->set_code(isolate()->builtins()->builtin(Builtins::kIllegal));
Zone zone;
// Build a "hybrid" CompilationInfo for a JSFunction/CodeStub pair.
ParseInfo parse_info(&zone, GetFunction(isolate(), GetFunctionName()));
ParseInfo parse_info(&zone, inner);
CompilationInfo info(&parse_info);
info.SetStub(this);
return info.GenerateCodeStub();
......
......@@ -355,11 +355,6 @@ struct FakeStubForTesting : public CodeStub {
Handle<Code> GenerateCode() override; \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \
public: \
const char* GetFunctionName() const override { return #NAME "_STUB"; } \
DEFINE_CODE_STUB(NAME, SUPER)
#define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \
public: \
Handle<Code> GenerateCode() override; \
......@@ -533,8 +528,6 @@ class TurboFanCodeStub : public CodeStub {
Code::StubType GetStubType() const override { return Code::FAST; }
virtual const char* GetFunctionName() const = 0;
protected:
explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {}
......@@ -615,7 +608,7 @@ class MathFloorStub : public TurboFanCodeStub {
int GetStackParameterCount() const override { return 1; }
DEFINE_CALL_INTERFACE_DESCRIPTOR(MathRoundVariant);
DEFINE_TURBOFAN_CODE_STUB(MathFloor, TurboFanCodeStub);
DEFINE_CODE_STUB(MathFloor, TurboFanCodeStub);
};
......@@ -628,7 +621,7 @@ class StringLengthTFStub : public TurboFanCodeStub {
ExtraICState GetExtraICState() const override { return Code::LOAD_IC; }
DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector);
DEFINE_TURBOFAN_CODE_STUB(StringLengthTF, TurboFanCodeStub);
DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub);
};
......@@ -671,7 +664,7 @@ class StringAddTFStub : public TurboFanCodeStub {
void PrintBaseName(std::ostream& os) const override; // NOLINT
DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd);
DEFINE_TURBOFAN_CODE_STUB(StringAddTF, TurboFanCodeStub);
DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub);
};
......
......@@ -64,9 +64,9 @@ var TO_NUMBER;
var TO_STRING;
var TO_NAME;
var StringLengthTF_STUB;
var StringAddTF_STUB;
var MathFloor_STUB;
var StringLengthTFStub;
var StringAddTFStub;
var MathFloorStub;
var $defaultNumber;
var $defaultString;
......@@ -767,35 +767,44 @@ TO_NAME = function TO_NAME() {
-----------------------------------------------
*/
StringLengthTF_STUB = function StringLengthTF_STUB(receiver, name, i, v) {
// i and v are dummy parameters mandated by the InterfaceDescriptor,
// (LoadWithVectorDescriptor).
return %_StringGetLength(%_JSValueGetValue(receiver));
}
StringAddTF_STUB = function StringAddTF_STUB(left, right) {
return %StringAdd(left, right);
StringLengthTFStub = function StringLengthTFStub(call_conv, minor_key) {
var stub = function(receiver, name, i, v) {
// i and v are dummy parameters mandated by the InterfaceDescriptor,
// (LoadWithVectorDescriptor).
return %_StringGetLength(%_JSValueGetValue(receiver));
}
return stub;
}
MathFloor_STUB = function MathFloor_STUB(f, i, v) {
// |f| is calling function's JSFunction
// |i| is TypeFeedbackVector slot # of callee's CallIC for Math.floor call
// |v| is the value to floor
var r = %_MathFloor(+v);
if (%_IsMinusZero(r)) {
// Collect type feedback when the result of the floor is -0. This is
// accomplished by storing a sentinel in the second, "extra"
// TypeFeedbackVector slot corresponding to the Math.floor CallIC call in
// the caller's TypeVector.
%_FixedArraySet(%_GetTypeFeedbackVector(f), ((i|0)+1)|0, 1);
return -0;
StringAddTFStub = function StringAddTFStub(call_conv, minor_key) {
var stub = function(left, right) {
return %StringAdd(left, right);
}
// Return integers in smi range as smis.
var trunc = r|0;
if (trunc === r) {
return trunc;
return stub;
}
MathFloorStub = function MathFloorStub(call_conv, minor_key) {
var stub = function(f, i, v) {
// |f| is calling function's JSFunction
// |i| is TypeFeedbackVector slot # of callee's CallIC for Math.floor call
// |v| is the value to floor
var r = %_MathFloor(+v);
if (%_IsMinusZero(r)) {
// Collect type feedback when the result of the floor is -0. This is
// accomplished by storing a sentinel in the second, "extra"
// TypeFeedbackVector slot corresponding to the Math.floor CallIC call in
// the caller's TypeVector.
%_FixedArraySet(%_GetTypeFeedbackVector(f), ((i|0)+1)|0, 1);
return -0;
}
// Return integers in smi range as smis.
var trunc = r|0;
if (trunc === r) {
return trunc;
}
return r;
}
return r;
return stub;
}
......
......@@ -36,16 +36,17 @@ const kFirstSlotExtraTypeFeedbackIndex = 5;
}
// Execute the function once to make sure it has a type feedback vector.
floorFunc(5);
var stub = builtins.MathFloorStub("MathFloorStub", 0);
assertTrue(kExtraTypeFeedbackMinusZeroSentinel !==
%FixedArrayGet(%GetTypeFeedbackVector(floorFunc),
kFirstSlotExtraTypeFeedbackIndex));
assertEquals(5.0, builtins.MathFloor_STUB(floorFunc, 4, 5.5));
assertEquals(5.0, stub(floorFunc, 4, 5.5));
assertTrue(kExtraTypeFeedbackMinusZeroSentinel !==
%FixedArrayGet(%GetTypeFeedbackVector(floorFunc),
kFirstSlotExtraTypeFeedbackIndex));
// Executing floor such that it returns -0 should set the proper sentinel in
// the feedback vector.
assertEquals(-Infinity, 1/builtins.MathFloor_STUB(floorFunc, 4, -0));
assertEquals(-Infinity, 1/stub(floorFunc, 4, -0));
assertEquals(kExtraTypeFeedbackMinusZeroSentinel,
%FixedArrayGet(%GetTypeFeedbackVector(floorFunc),
kFirstSlotExtraTypeFeedbackIndex));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment