Commit 7ca1f80d authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[runtime] Fix number of literals for builtin functions.

This fixes the SharedFunctionInfo::num_literals field for global builtin
functions (e.g. {Object} and friends) to be accurate. The field was not
being updated by Runtime_SetCode. It also removes the dangerous and by
now obsolete JSFunction::NumberOfLiterals accessor.

R=mvstanton@chromium.org

Review-Url: https://codereview.chromium.org/2007943002
Cr-Commit-Position: refs/heads/master@{#36480}
parent 796db52f
......@@ -1686,11 +1686,10 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative(
Handle<JSFunction> fun = Handle<JSFunction>::cast(Utils::OpenHandle(
*fun_template->GetFunction(v8_isolate->GetCurrentContext())
.ToLocalChecked()));
const int literals = fun->NumberOfLiterals();
Handle<Code> code = Handle<Code>(fun->shared()->code());
Handle<Code> construct_stub = Handle<Code>(fun->shared()->construct_stub());
Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
name, literals, FunctionKind::kNormalFunction, code,
name, fun->shared()->num_literals(), FunctionKind::kNormalFunction, code,
Handle<ScopeInfo>(fun->shared()->scope_info()));
shared->set_construct_stub(*construct_stub);
shared->set_feedback_vector(fun->shared()->feedback_vector());
......
......@@ -6238,11 +6238,6 @@ bool JSFunction::is_compiled() {
}
int JSFunction::NumberOfLiterals() {
return literals()->length();
}
ACCESSORS(JSProxy, target, JSReceiver, kTargetOffset)
ACCESSORS(JSProxy, handler, Object, kHandlerOffset)
ACCESSORS(JSProxy, hash, Object, kHashOffset)
......
......@@ -916,6 +916,7 @@ void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) { // NOLINT
os << "\n - end position = " << end_position();
os << "\n - debug info = " << Brief(debug_info());
os << "\n - length = " << length();
os << "\n - num_literals = " << num_literals();
os << "\n - optimized_code_map = " << Brief(optimized_code_map());
os << "\n - feedback_vector = ";
feedback_vector()->TypeFeedbackVectorPrint(os);
......
......@@ -7569,9 +7569,6 @@ class JSFunction: public JSObject {
DECLARE_PRINTER(JSFunction)
DECLARE_VERIFIER(JSFunction)
// Returns the number of allocated literals.
inline int NumberOfLiterals();
// The function's name if it is configured, otherwise shared function info
// debug name.
static Handle<String> GetName(Handle<JSFunction> function);
......
......@@ -187,6 +187,7 @@ RUNTIME_FUNCTION(Runtime_SetCode) {
}
target_shared->set_scope_info(source_shared->scope_info());
target_shared->set_length(source_shared->length());
target_shared->set_num_literals(source_shared->num_literals());
target_shared->set_feedback_vector(source_shared->feedback_vector());
target_shared->set_internal_formal_parameter_count(
source_shared->internal_formal_parameter_count());
......@@ -211,10 +212,9 @@ RUNTIME_FUNCTION(Runtime_SetCode) {
Handle<Context> context(source->context());
target->set_context(*context);
int number_of_literals = source->NumberOfLiterals();
Handle<LiteralsArray> literals =
LiteralsArray::New(isolate, handle(target_shared->feedback_vector()),
number_of_literals, TENURED);
target_shared->num_literals(), TENURED);
target->set_literals(*literals);
if (isolate->logger()->is_logging_code_events() ||
......
......@@ -139,7 +139,7 @@ TEST_F(JSCreateLoweringTest, JSCreateClosureViaInlinedAllocation) {
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
Handle<SharedFunctionInfo> shared(isolate()->object_function()->shared());
Handle<SharedFunctionInfo> shared(isolate()->number_function()->shared());
Reduction r =
Reduce(graph()->NewNode(javascript()->CreateClosure(shared, NOT_TENURED),
context, effect, control));
......
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