OLD | NEW |
---|---|
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 Loading... | |
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 source_shared->code()->set_optimizable(false); | |
2203 target_shared->code()->set_optimizable(false); | |
ulan
2012/06/06 09:44:15
target_share->code() == source_shared->code() at t
Michael Starzinger
2012/06/06 09:51:01
Done. It was a leftover from the original version.
| |
2204 | |
2205 // Clear the optimization hints related to the compiled code as these | |
2206 // are no longer valid when the code is overwritten. | |
2207 target_shared->ClearThisPropertyAssignmentsInfo(); | |
2208 | |
2209 // Set the code of the target function. | |
2210 target->ReplaceCode(source_shared->code()); | |
2211 | |
2212 // Make sure we get a fresh copy of the literal vector to avoid cross | |
2213 // context contamination. | |
2214 Handle<Context> context(source->context()); | |
2215 int number_of_literals = source->NumberOfLiterals(); | |
2216 Handle<FixedArray> literals = | |
2217 isolate->factory()->NewFixedArray(number_of_literals, TENURED); | |
2218 if (number_of_literals > 0) { | |
2219 literals->set(JSFunction::kLiteralGlobalContextIndex, | |
2220 context->global_context()); | |
2221 } | |
2231 target->set_context(*context); | 2222 target->set_context(*context); |
2223 target->set_literals(*literals); | |
2224 target->set_next_function_link(isolate->heap()->undefined_value()); | |
2225 | |
2226 if (isolate->logger()->is_logging() || CpuProfiler::is_profiling(isolate)) { | |
2227 isolate->logger()->LogExistingFunction( | |
2228 source_shared, Handle<Code>(source_shared->code())); | |
2229 } | |
2230 | |
2232 return *target; | 2231 return *target; |
2233 } | 2232 } |
2234 | 2233 |
2235 | 2234 |
2236 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetExpectedNumberOfProperties) { | 2235 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetExpectedNumberOfProperties) { |
2237 HandleScope scope(isolate); | 2236 HandleScope scope(isolate); |
2238 ASSERT(args.length() == 2); | 2237 ASSERT(args.length() == 2); |
2239 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 2238 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
2240 CONVERT_SMI_ARG_CHECKED(num, 1); | 2239 CONVERT_SMI_ARG_CHECKED(num, 1); |
2241 RUNTIME_ASSERT(num >= 0); | 2240 RUNTIME_ASSERT(num >= 0); |
(...skipping 11321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13563 // Handle last resort GC and make sure to allow future allocations | 13562 // Handle last resort GC and make sure to allow future allocations |
13564 // to grow the heap without causing GCs (if possible). | 13563 // to grow the heap without causing GCs (if possible). |
13565 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13564 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13566 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13565 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13567 "Runtime::PerformGC"); | 13566 "Runtime::PerformGC"); |
13568 } | 13567 } |
13569 } | 13568 } |
13570 | 13569 |
13571 | 13570 |
13572 } } // namespace v8::internal | 13571 } } // namespace v8::internal |
OLD | NEW |