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

Side by Side Diff: src/runtime.cc

Issue 8133020: Simplify calling generated code from the runtime. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 2 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 7903 matching lines...) Expand 10 before | Expand all | Expand 10 after
7914 // directly to properties. 7914 // directly to properties.
7915 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; 7915 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED;
7916 Handle<JSFunction> result = 7916 Handle<JSFunction> result =
7917 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, 7917 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared,
7918 context, 7918 context,
7919 pretenure_flag); 7919 pretenure_flag);
7920 return *result; 7920 return *result;
7921 } 7921 }
7922 7922
7923 7923
7924 static SmartArrayPointer<Object**> GetNonBoundArguments(int bound_argc, 7924 static SmartArrayPointer<Handle<Object> > GetNonBoundArguments(
7925 int* total_argc) { 7925 int bound_argc,
7926 int* total_argc) {
7926 // Find frame containing arguments passed to the caller. 7927 // Find frame containing arguments passed to the caller.
7927 JavaScriptFrameIterator it; 7928 JavaScriptFrameIterator it;
7928 JavaScriptFrame* frame = it.frame(); 7929 JavaScriptFrame* frame = it.frame();
7929 List<JSFunction*> functions(2); 7930 List<JSFunction*> functions(2);
7930 frame->GetFunctions(&functions); 7931 frame->GetFunctions(&functions);
7931 if (functions.length() > 1) { 7932 if (functions.length() > 1) {
7932 int inlined_frame_index = functions.length() - 1; 7933 int inlined_frame_index = functions.length() - 1;
7933 JSFunction* inlined_function = functions[inlined_frame_index]; 7934 JSFunction* inlined_function = functions[inlined_frame_index];
7934 int args_count = inlined_function->shared()->formal_parameter_count(); 7935 int args_count = inlined_function->shared()->formal_parameter_count();
7935 ScopedVector<SlotRef> args_slots(args_count); 7936 ScopedVector<SlotRef> args_slots(args_count);
7936 SlotRef::ComputeSlotMappingForArguments(frame, 7937 SlotRef::ComputeSlotMappingForArguments(frame,
7937 inlined_frame_index, 7938 inlined_frame_index,
7938 &args_slots); 7939 &args_slots);
7939 7940
7940 *total_argc = bound_argc + args_count; 7941 *total_argc = bound_argc + args_count;
7941 SmartArrayPointer<Object**> param_data(NewArray<Object**>(*total_argc)); 7942 SmartArrayPointer<Handle<Object> > param_data(
7943 NewArray<Handle<Object> >(*total_argc));
7942 for (int i = 0; i < args_count; i++) { 7944 for (int i = 0; i < args_count; i++) {
7943 Handle<Object> val = args_slots[i].GetValue(); 7945 Handle<Object> val = args_slots[i].GetValue();
7944 param_data[bound_argc + i] = val.location(); 7946 param_data[bound_argc + i] = val;
7945 } 7947 }
7946 return param_data; 7948 return param_data;
7947 } else { 7949 } else {
7948 it.AdvanceToArgumentsFrame(); 7950 it.AdvanceToArgumentsFrame();
7949 frame = it.frame(); 7951 frame = it.frame();
7950 int args_count = frame->ComputeParametersCount(); 7952 int args_count = frame->ComputeParametersCount();
7951 7953
7952 *total_argc = bound_argc + args_count; 7954 *total_argc = bound_argc + args_count;
7953 SmartArrayPointer<Object**> param_data(NewArray<Object**>(*total_argc)); 7955 SmartArrayPointer<Handle<Object> > param_data(
7956 NewArray<Handle<Object> >(*total_argc));
7954 for (int i = 0; i < args_count; i++) { 7957 for (int i = 0; i < args_count; i++) {
7955 Handle<Object> val = Handle<Object>(frame->GetParameter(i)); 7958 Handle<Object> val = Handle<Object>(frame->GetParameter(i));
7956 param_data[bound_argc + i] = val.location(); 7959 param_data[bound_argc + i] = val;
7957 } 7960 }
7958 return param_data; 7961 return param_data;
7959 } 7962 }
7960 } 7963 }
7961 7964
7962 7965
7963 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObjectFromBound) { 7966 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewObjectFromBound) {
7964 HandleScope scope(isolate); 7967 HandleScope scope(isolate);
7965 ASSERT(args.length() == 2); 7968 ASSERT(args.length() == 2);
7966 // First argument is a function to use as a constructor. 7969 // First argument is a function to use as a constructor.
7967 CONVERT_ARG_CHECKED(JSFunction, function, 0); 7970 CONVERT_ARG_CHECKED(JSFunction, function, 0);
7968 7971
7969 // Second argument is either null or an array of bound arguments. 7972 // Second argument is either null or an array of bound arguments.
7970 Handle<FixedArray> bound_args; 7973 Handle<FixedArray> bound_args;
7971 int bound_argc = 0; 7974 int bound_argc = 0;
7972 if (!args[1]->IsNull()) { 7975 if (!args[1]->IsNull()) {
7973 CONVERT_ARG_CHECKED(JSArray, params, 1); 7976 CONVERT_ARG_CHECKED(JSArray, params, 1);
7974 RUNTIME_ASSERT(params->HasFastTypeElements()); 7977 RUNTIME_ASSERT(params->HasFastTypeElements());
7975 bound_args = Handle<FixedArray>(FixedArray::cast(params->elements())); 7978 bound_args = Handle<FixedArray>(FixedArray::cast(params->elements()));
7976 bound_argc = Smi::cast(params->length())->value(); 7979 bound_argc = Smi::cast(params->length())->value();
7977 } 7980 }
7978 7981
7979 int total_argc = 0; 7982 int total_argc = 0;
7980 SmartArrayPointer<Object**> param_data = 7983 SmartArrayPointer<Handle<Object> > param_data =
7981 GetNonBoundArguments(bound_argc, &total_argc); 7984 GetNonBoundArguments(bound_argc, &total_argc);
7982 for (int i = 0; i < bound_argc; i++) { 7985 for (int i = 0; i < bound_argc; i++) {
7983 Handle<Object> val = Handle<Object>(bound_args->get(i)); 7986 Handle<Object> val = Handle<Object>(bound_args->get(i));
7984 param_data[i] = val.location(); 7987 param_data[i] = val;
7985 } 7988 }
7986 7989
7987 bool exception = false; 7990 bool exception = false;
7988 Handle<Object> result = 7991 Handle<Object> result =
7989 Execution::New(function, total_argc, *param_data, &exception); 7992 Execution::New(function, total_argc, *param_data, &exception);
7990 if (exception) { 7993 if (exception) {
7991 return Failure::Exception(); 7994 return Failure::Exception();
7992 } 7995 }
7993 7996
7994 ASSERT(!result.is_null()); 7997 ASSERT(!result.is_null());
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
8451 for (int i = 0; i < argc; ++i) { 8454 for (int i = 0; i < argc; ++i) {
8452 MaybeObject* maybe = arguments->GetElement(offset + i); 8455 MaybeObject* maybe = arguments->GetElement(offset + i);
8453 Object* object; 8456 Object* object;
8454 if (!maybe->To<Object>(&object)) return maybe; 8457 if (!maybe->To<Object>(&object)) return maybe;
8455 argv[i] = Handle<Object>(object); 8458 argv[i] = Handle<Object>(object);
8456 } 8459 }
8457 8460
8458 bool threw; 8461 bool threw;
8459 Handle<JSReceiver> hfun(fun); 8462 Handle<JSReceiver> hfun(fun);
8460 Handle<Object> hreceiver(receiver); 8463 Handle<Object> hreceiver(receiver);
8461 Handle<Object> result = Execution::Call( 8464 Handle<Object> result =
8462 hfun, hreceiver, argc, reinterpret_cast<Object***>(argv), &threw, true); 8465 Execution::Call(hfun, hreceiver, argc, argv, &threw, true);
8463 8466
8464 if (threw) return Failure::Exception(); 8467 if (threw) return Failure::Exception();
8465 return *result; 8468 return *result;
8466 } 8469 }
8467 8470
8468 8471
8469 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionDelegate) { 8472 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionDelegate) {
8470 HandleScope scope(isolate); 8473 HandleScope scope(isolate);
8471 ASSERT(args.length() == 1); 8474 ASSERT(args.length() == 1);
8472 RUNTIME_ASSERT(!args[0]->IsJSFunction()); 8475 RUNTIME_ASSERT(!args[0]->IsJSFunction());
(...skipping 3369 matching lines...) Expand 10 before | Expand all | Expand 10 after
11842 Execution::Call(compiled_function, receiver, 0, NULL, 11845 Execution::Call(compiled_function, receiver, 0, NULL,
11843 &has_pending_exception); 11846 &has_pending_exception);
11844 if (has_pending_exception) return Failure::Exception(); 11847 if (has_pending_exception) return Failure::Exception();
11845 11848
11846 Handle<Object> arguments = GetArgumentsObject(isolate, 11849 Handle<Object> arguments = GetArgumentsObject(isolate,
11847 frame, inlined_frame_index, 11850 frame, inlined_frame_index,
11848 function, scope_info, 11851 function, scope_info,
11849 &sinfo, function_context); 11852 &sinfo, function_context);
11850 11853
11851 // Invoke the evaluation function and return the result. 11854 // Invoke the evaluation function and return the result.
11852 const int argc = 2; 11855 Handle<Object> argv[] = { arguments, source };
11853 Object** argv[argc] = { arguments.location(),
11854 Handle<Object>::cast(source).location() };
11855 Handle<Object> result = 11856 Handle<Object> result =
11856 Execution::Call(Handle<JSFunction>::cast(evaluation_function), receiver, 11857 Execution::Call(Handle<JSFunction>::cast(evaluation_function),
11857 argc, argv, &has_pending_exception); 11858 receiver,
11859 ARRAY_SIZE(argv),
11860 argv,
11861 &has_pending_exception);
11858 if (has_pending_exception) return Failure::Exception(); 11862 if (has_pending_exception) return Failure::Exception();
11859 11863
11860 // Skip the global proxy as it has no properties and always delegates to the 11864 // Skip the global proxy as it has no properties and always delegates to the
11861 // real global object. 11865 // real global object.
11862 if (result->IsJSGlobalProxy()) { 11866 if (result->IsJSGlobalProxy()) {
11863 result = Handle<JSObject>(JSObject::cast(result->GetPrototype())); 11867 result = Handle<JSObject>(JSObject::cast(result->GetPrototype()));
11864 } 11868 }
11865 11869
11866 return *result; 11870 return *result;
11867 } 11871 }
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
12982 12986
12983 Handle<JSFunctionResultCache> cache_handle(cache); 12987 Handle<JSFunctionResultCache> cache_handle(cache);
12984 Handle<Object> key_handle(key); 12988 Handle<Object> key_handle(key);
12985 Handle<Object> value; 12989 Handle<Object> value;
12986 { 12990 {
12987 Handle<JSFunction> factory(JSFunction::cast( 12991 Handle<JSFunction> factory(JSFunction::cast(
12988 cache_handle->get(JSFunctionResultCache::kFactoryIndex))); 12992 cache_handle->get(JSFunctionResultCache::kFactoryIndex)));
12989 // TODO(antonm): consider passing a receiver when constructing a cache. 12993 // TODO(antonm): consider passing a receiver when constructing a cache.
12990 Handle<Object> receiver(isolate->global_context()->global()); 12994 Handle<Object> receiver(isolate->global_context()->global());
12991 // This handle is nor shared, nor used later, so it's safe. 12995 // This handle is nor shared, nor used later, so it's safe.
12992 Object** argv[] = { key_handle.location() }; 12996 Handle<Object> argv[] = { key_handle };
12993 bool pending_exception; 12997 bool pending_exception;
12994 value = Execution::Call(factory, 12998 value = Execution::Call(factory,
12995 receiver, 12999 receiver,
12996 1, 13000 ARRAY_SIZE(argv),
12997 argv, 13001 argv,
12998 &pending_exception); 13002 &pending_exception);
12999 if (pending_exception) return Failure::Exception(); 13003 if (pending_exception) return Failure::Exception();
13000 } 13004 }
13001 13005
13002 #ifdef DEBUG 13006 #ifdef DEBUG
13003 cache_handle->JSFunctionResultCacheVerify(); 13007 cache_handle->JSFunctionResultCacheVerify();
13004 #endif 13008 #endif
13005 13009
13006 // Function invocation may have cleared the cache. Reread all the data. 13010 // Function invocation may have cleared the cache. Reread all the data.
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
13239 } else { 13243 } else {
13240 // Handle last resort GC and make sure to allow future allocations 13244 // Handle last resort GC and make sure to allow future allocations
13241 // to grow the heap without causing GCs (if possible). 13245 // to grow the heap without causing GCs (if possible).
13242 isolate->counters()->gc_last_resort_from_js()->Increment(); 13246 isolate->counters()->gc_last_resort_from_js()->Increment();
13243 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13247 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13244 } 13248 }
13245 } 13249 }
13246 13250
13247 13251
13248 } } // namespace v8::internal 13252 } } // namespace v8::internal
OLDNEW
« src/ic.cc ('K') | « src/objects.cc ('k') | test/cctest/test-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698