Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/runtime.cc

Issue 10544025: Cleanup Runtime_SetCode and drop EnsureCompiled. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Ulan Degenbaev. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 } 2168 }
2169 2169
2170 2170
2171 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetCode) { 2171 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetCode) {
2172 HandleScope scope(isolate); 2172 HandleScope scope(isolate);
2173 ASSERT(args.length() == 2); 2173 ASSERT(args.length() == 2);
2174 2174
2175 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0); 2175 CONVERT_ARG_HANDLE_CHECKED(JSFunction, target, 0);
2176 Handle<Object> code = args.at<Object>(1); 2176 Handle<Object> code = args.at<Object>(1);
2177 2177
2178 Handle<Context> context(target->context()); 2178 if (code->IsNull()) return *target;
2179 RUNTIME_ASSERT(code->IsJSFunction());
2180 Handle<JSFunction> source = Handle<JSFunction>::cast(code);
2181 Handle<SharedFunctionInfo> target_shared(target->shared());
2182 Handle<SharedFunctionInfo> source_shared(source->shared());
2179 2183
2180 if (!code->IsNull()) { 2184 if (!source->is_compiled() &&
2181 RUNTIME_ASSERT(code->IsJSFunction()); 2185 !JSFunction::CompileLazy(source, KEEP_EXCEPTION)) {
2182 Handle<JSFunction> fun = Handle<JSFunction>::cast(code); 2186 return Failure::Exception();
2183 Handle<SharedFunctionInfo> shared(fun->shared());
2184
2185 if (!SharedFunctionInfo::EnsureCompiled(shared, KEEP_EXCEPTION)) {
2186 return Failure::Exception();
2187 }
2188 // Since we don't store the source for this we should never
2189 // optimize this.
2190 shared->code()->set_optimizable(false);
2191 // Set the code, scope info, formal parameter count,
2192 // and the length of the target function.
2193 target->shared()->set_code(shared->code());
2194 target->ReplaceCode(shared->code());
2195 target->shared()->set_scope_info(shared->scope_info());
2196 target->shared()->set_length(shared->length());
2197 target->shared()->set_formal_parameter_count(
2198 shared->formal_parameter_count());
2199 // Set the source code of the target function to undefined.
2200 // SetCode is only used for built-in constructors like String,
2201 // Array, and Object, and some web code
2202 // doesn't like seeing source code for constructors.
2203 target->shared()->set_script(isolate->heap()->undefined_value());
2204 target->shared()->code()->set_optimizable(false);
2205 // Clear the optimization hints related to the compiled code as these are no
2206 // longer valid when the code is overwritten.
2207 target->shared()->ClearThisPropertyAssignmentsInfo();
2208 context = Handle<Context>(fun->context());
2209
2210 // Make sure we get a fresh copy of the literal vector to avoid
2211 // cross context contamination.
2212 int number_of_literals = fun->NumberOfLiterals();
2213 Handle<FixedArray> literals =
2214 isolate->factory()->NewFixedArray(number_of_literals, TENURED);
2215 if (number_of_literals > 0) {
2216 // Insert the object, regexp and array functions in the literals
2217 // array prefix. These are the functions that will be used when
2218 // creating object, regexp and array literals.
2219 literals->set(JSFunction::kLiteralGlobalContextIndex,
2220 context->global_context());
2221 }
2222 target->set_literals(*literals);
2223 target->set_next_function_link(isolate->heap()->undefined_value());
2224
2225 if (isolate->logger()->is_logging() || CpuProfiler::is_profiling(isolate)) {
2226 isolate->logger()->LogExistingFunction(
2227 shared, Handle<Code>(shared->code()));
2228 }
2229 } 2187 }
2230 2188
2189 // Set the code, scope info, formal parameter count, and the length
2190 // of the target shared function info. Set the source code of the
2191 // target function to undefined. SetCode is only used for built-in
2192 // constructors like String, Array, and Object, and some web code
2193 // doesn't like seeing source code for constructors.
2194 target_shared->set_code(source_shared->code());
2195 target_shared->set_scope_info(source_shared->scope_info());
2196 target_shared->set_length(source_shared->length());
2197 target_shared->set_formal_parameter_count(
2198 source_shared->formal_parameter_count());
2199 target_shared->set_script(isolate->heap()->undefined_value());
2200
2201 // Since we don't store the source we should never optimize this.
2202 target_shared->code()->set_optimizable(false);
2203
2204 // Clear the optimization hints related to the compiled code as these
2205 // are no longer valid when the code is overwritten.
2206 target_shared->ClearThisPropertyAssignmentsInfo();
2207
2208 // Set the code of the target function.
2209 target->ReplaceCode(source_shared->code());
2210
2211 // Make sure we get a fresh copy of the literal vector to avoid cross
2212 // context contamination.
2213 Handle<Context> context(source->context());
2214 int number_of_literals = source->NumberOfLiterals();
2215 Handle<FixedArray> literals =
2216 isolate->factory()->NewFixedArray(number_of_literals, TENURED);
2217 if (number_of_literals > 0) {
2218 literals->set(JSFunction::kLiteralGlobalContextIndex,
2219 context->global_context());
2220 }
2231 target->set_context(*context); 2221 target->set_context(*context);
2222 target->set_literals(*literals);
2223 target->set_next_function_link(isolate->heap()->undefined_value());
2224
2225 if (isolate->logger()->is_logging() || CpuProfiler::is_profiling(isolate)) {
2226 isolate->logger()->LogExistingFunction(
2227 source_shared, Handle<Code>(source_shared->code()));
2228 }
2229
2232 return *target; 2230 return *target;
2233 } 2231 }
2234 2232
2235 2233
2236 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetExpectedNumberOfProperties) { 2234 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetExpectedNumberOfProperties) {
2237 HandleScope scope(isolate); 2235 HandleScope scope(isolate);
2238 ASSERT(args.length() == 2); 2236 ASSERT(args.length() == 2);
2239 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 2237 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
2240 CONVERT_SMI_ARG_CHECKED(num, 1); 2238 CONVERT_SMI_ARG_CHECKED(num, 1);
2241 RUNTIME_ASSERT(num >= 0); 2239 RUNTIME_ASSERT(num >= 0);
(...skipping 11321 matching lines...) Expand 10 before | Expand all | Expand 10 after
13563 // Handle last resort GC and make sure to allow future allocations 13561 // Handle last resort GC and make sure to allow future allocations
13564 // to grow the heap without causing GCs (if possible). 13562 // to grow the heap without causing GCs (if possible).
13565 isolate->counters()->gc_last_resort_from_js()->Increment(); 13563 isolate->counters()->gc_last_resort_from_js()->Increment();
13566 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13564 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13567 "Runtime::PerformGC"); 13565 "Runtime::PerformGC");
13568 } 13566 }
13569 } 13567 }
13570 13568
13571 13569
13572 } } // namespace v8::internal 13570 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698