__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
// -----------------------------------
SharedFunctionInfo* function_info = function->shared();
if (function_info->HasCustomCallGenerator()) {
- CustomCallGenerator generator =
- ToCData<CustomCallGenerator>(function_info->function_data());
- Object* result = generator(this, object, holder, function, name, check);
+ const int id = function_info->custom_call_generator_id();
+ Object* result =
+ CompileCustomCall(id, object, holder, function, name, check);
// undefined means bail out to regular compiler.
if (!result->IsUndefined()) {
return result;
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
}
-ExternalReference ExternalReference::compile_array_pop_call() {
- return ExternalReference(FUNCTION_ADDR(CompileArrayPopCall));
-}
-
-
-ExternalReference ExternalReference::compile_array_push_call() {
- return ExternalReference(FUNCTION_ADDR(CompileArrayPushCall));
-}
-
-
#ifndef V8_INTERPRETED_REGEXP
ExternalReference ExternalReference::re_check_stack_guard_state() {
static ExternalReference scheduled_exception_address();
- static ExternalReference compile_array_pop_call();
- static ExternalReference compile_array_push_call();
-
Address address() const {return reinterpret_cast<Address>(address_);}
#ifdef ENABLE_DEBUGGER_SUPPORT
#include "macro-assembler.h"
#include "natives.h"
#include "snapshot.h"
+#include "stub-cache.h"
namespace v8 {
namespace internal {
// Used for creating a context from scratch.
void InstallNativeFunctions();
bool InstallNatives();
+ void InstallCustomCallGenerators();
void InstallJSFunctionResultCaches();
// Used both for deserialized and from-scratch contexts to add the extensions
// provided.
InstallNativeFunctions();
+ InstallCustomCallGenerators();
+
// Install Function.prototype.call and apply.
{ Handle<String> key = Factory::function_class_symbol();
Handle<JSFunction> function =
}
+static void InstallCustomCallGenerator(Handle<JSFunction> holder_function,
+ const char* function_name,
+ int id) {
+ Handle<JSObject> proto(JSObject::cast(holder_function->instance_prototype()));
+ Handle<String> name = Factory::LookupAsciiSymbol(function_name);
+ Handle<JSFunction> function(JSFunction::cast(proto->GetProperty(*name)));
+ function->shared()->set_function_data(Smi::FromInt(id));
+}
+
+
+void Genesis::InstallCustomCallGenerators() {
+ HandleScope scope;
+#define INSTALL_CALL_GENERATOR(holder_fun, fun_name, name) \
+ { \
+ Handle<JSFunction> holder(global_context()->holder_fun##_function()); \
+ const int id = CallStubCompiler::k##name##CallGenerator; \
+ InstallCustomCallGenerator(holder, #fun_name, id); \
+ }
+ CUSTOM_CALL_IC_GENERATORS(INSTALL_CALL_GENERATOR)
+#undef INSTALL_CALL_GENERATOR
+}
+
+
// Do not forget to update macros.py with named constant
// of cache id.
#define JSFUNCTION_RESULT_CACHE_LIST(F) \
}
__ bind(&miss);
-
Handle<Code> ic = ComputeCallMiss(arguments().immediate());
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
1);
__ bind(&miss);
-
Handle<Code> ic = ComputeCallMiss(arguments().immediate());
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
SharedFunctionInfo* function_info = function->shared();
if (function_info->HasCustomCallGenerator()) {
- CustomCallGenerator generator =
- ToCData<CustomCallGenerator>(function_info->function_data());
- Object* result = generator(this, object, holder, function, name, check);
+ const int id = function_info->custom_call_generator_id();
+ Object* result =
+ CompileCustomCall(id, object, holder, function, name, check);
// undefined means bail out to regular compiler.
if (!result->IsUndefined()) {
return result;
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
bool SharedFunctionInfo::HasCustomCallGenerator() {
- return function_data()->IsProxy();
+ return function_data()->IsSmi();
+}
+
+
+int SharedFunctionInfo::custom_call_generator_id() {
+ ASSERT(HasCustomCallGenerator());
+ return Smi::cast(function_data())->value();
}
// [function data]: This field holds some additional data for function.
// Currently it either has FunctionTemplateInfo to make benefit the API
- // or Proxy wrapping CustomCallGenerator.
+ // or Smi identifying a custom call generator.
// In the long run we don't want all functions to have this field but
// we can fix that when we have a better model for storing hidden data
// on objects.
inline bool IsApiFunction();
inline FunctionTemplateInfo* get_api_func_data();
inline bool HasCustomCallGenerator();
+ inline int custom_call_generator_id();
// [script info]: Script from which the function originates.
DECL_ACCESSORS(script, Object)
}
-static void SetCustomCallGenerator(Handle<JSFunction> function,
- ExternalReference* generator) {
- if (function->shared()->function_data()->IsUndefined()) {
- function->shared()->set_function_data(*FromCData(generator->address()));
- }
-}
-
-
static Handle<JSFunction> InstallBuiltin(Handle<JSObject> holder,
const char* name,
- Builtins::Name builtin_name,
- ExternalReference* generator = NULL) {
+ Builtins::Name builtin_name) {
Handle<String> key = Factory::LookupAsciiSymbol(name);
Handle<Code> code(Builtins::builtin(builtin_name));
Handle<JSFunction> optimized = Factory::NewFunction(key,
code,
false);
optimized->shared()->DontAdaptArguments();
- if (generator != NULL) {
- SetCustomCallGenerator(optimized, generator);
- }
SetProperty(holder, key, optimized, NONE);
return optimized;
}
-Object* CompileArrayPushCall(CallStubCompiler* compiler,
- Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
- StubCompiler::CheckType check) {
- return compiler->CompileArrayPushCall(object, holder, function, name, check);
-}
-
-
-Object* CompileArrayPopCall(CallStubCompiler* compiler,
- Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
- StubCompiler::CheckType check) {
- return compiler->CompileArrayPopCall(object, holder, function, name, check);
-}
-
-
static Object* Runtime_SpecialArrayFunctions(Arguments args) {
HandleScope scope;
ASSERT(args.length() == 1);
CONVERT_ARG_CHECKED(JSObject, holder, 0);
- ExternalReference pop = ExternalReference::compile_array_pop_call();
- ExternalReference push = ExternalReference::compile_array_push_call();
-
- InstallBuiltin(holder, "pop", Builtins::ArrayPop, &pop);
- InstallBuiltin(holder, "push", Builtins::ArrayPush, &push);
+ InstallBuiltin(holder, "pop", Builtins::ArrayPop);
+ InstallBuiltin(holder, "push", Builtins::ArrayPush);
InstallBuiltin(holder, "shift", Builtins::ArrayShift);
InstallBuiltin(holder, "unshift", Builtins::ArrayUnshift);
InstallBuiltin(holder, "slice", Builtins::ArraySlice);
UNCLASSIFIED,
19,
"compare_doubles");
- Add(ExternalReference::compile_array_pop_call().address(),
- UNCLASSIFIED,
- 20,
- "compile_array_pop");
- Add(ExternalReference::compile_array_push_call().address(),
- UNCLASSIFIED,
- 21,
- "compile_array_push");
#ifndef V8_INTERPRETED_REGEXP
Add(ExternalReference::re_case_insensitive_compare_uc16().address(),
UNCLASSIFIED,
- 22,
+ 20,
"NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()");
Add(ExternalReference::re_check_stack_guard_state().address(),
UNCLASSIFIED,
- 23,
+ 21,
"RegExpMacroAssembler*::CheckStackGuardState()");
Add(ExternalReference::re_grow_stack().address(),
UNCLASSIFIED,
- 24,
+ 22,
"NativeRegExpMacroAssembler::GrowStack()");
Add(ExternalReference::re_word_character_map().address(),
UNCLASSIFIED,
- 25,
+ 23,
"NativeRegExpMacroAssembler::word_character_map");
#endif // V8_INTERPRETED_REGEXP
// Keyed lookup cache.
Add(ExternalReference::keyed_lookup_cache_keys().address(),
UNCLASSIFIED,
- 26,
+ 24,
"KeyedLookupCache::keys()");
Add(ExternalReference::keyed_lookup_cache_field_offsets().address(),
UNCLASSIFIED,
- 27,
+ 25,
"KeyedLookupCache::field_offsets()");
Add(ExternalReference::transcendental_cache_array_address().address(),
UNCLASSIFIED,
- 28,
+ 26,
"TranscendentalCache::caches()");
}
}
+Object* CallStubCompiler::CompileCustomCall(int generator_id,
+ Object* object,
+ JSObject* holder,
+ JSFunction* function,
+ String* fname,
+ CheckType check) {
+ ASSERT(generator_id >= 0 && generator_id < kNumCallGenerators);
+ switch (generator_id) {
+#define CALL_GENERATOR_CASE(ignored1, ignored2, name) \
+ case k##name##CallGenerator: \
+ return CallStubCompiler::Compile##name##Call(object, \
+ holder, \
+ function, \
+ fname, \
+ check);
+ CUSTOM_CALL_IC_GENERATORS(CALL_GENERATOR_CASE)
+#undef CALL_GENERATOR_CASE
+ }
+ UNREACHABLE();
+ return Heap::undefined_value();
+}
+
+
Object* CallStubCompiler::GetCode(PropertyType type, String* name) {
int argc = arguments_.immediate();
Code::Flags flags = Code::ComputeMonomorphicFlags(Code::CALL_IC,
}
+Object* CallStubCompiler::GetCode(JSFunction* function) {
+ String* function_name = NULL;
+ if (function->shared()->name()->IsString()) {
+ function_name = String::cast(function->shared()->name());
+ }
+ return GetCode(CONSTANT_FUNCTION, function_name);
+}
+
+
Object* ConstructStubCompiler::GetCode() {
Code::Flags flags = Code::ComputeFlags(Code::STUB);
Object* result = GetCodeWithFlags(flags, "ConstructStub");
};
+// List of functions with custom constant call IC stubs.
+//
+// Installation of custom call generators for the selected builtins is
+// handled by the bootstrapper.
+//
+// Each entry has a name of a global function (lowercased), a name of
+// a builtin function on its instance prototype (the one the generator
+// is set for), and a name of a generator itself (used to build ids
+// and generator function names).
+#define CUSTOM_CALL_IC_GENERATORS(V) \
+ V(array, push, ArrayPush) \
+ V(array, pop, ArrayPop)
+
+
class CallStubCompiler: public StubCompiler {
public:
+ enum {
+#define DECLARE_CALL_GENERATOR_ID(ignored1, ignored2, name) \
+ k##name##CallGenerator,
+ CUSTOM_CALL_IC_GENERATORS(DECLARE_CALL_GENERATOR_ID)
+#undef DECLARE_CALL_GENERATOR_ID
+ kNumCallGenerators
+ };
+
CallStubCompiler(int argc, InLoopFlag in_loop)
: arguments_(argc), in_loop_(in_loop) { }
JSFunction* function,
String* name);
- Object* CompileArrayPushCall(Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
- CheckType check);
+ // Compiles a custom call constant IC using the generator with given id.
+ Object* CompileCustomCall(int generator_id,
+ Object* object,
+ JSObject* holder,
+ JSFunction* function,
+ String* name,
+ CheckType check);
- Object* CompileArrayPopCall(Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
+#define DECLARE_CALL_GENERATOR(ignored1, ignored2, name) \
+ Object* Compile##name##Call(Object* object, \
+ JSObject* holder, \
+ JSFunction* function, \
+ String* fname, \
CheckType check);
+ CUSTOM_CALL_IC_GENERATORS(DECLARE_CALL_GENERATOR)
+#undef DECLARE_CALL_GENERATOR
private:
const ParameterCount arguments_;
const ParameterCount& arguments() { return arguments_; }
Object* GetCode(PropertyType type, String* name);
+
+ // Convenience function. Calls GetCode above passing
+ // CONSTANT_FUNCTION type and the name of the given function.
+ Object* GetCode(JSFunction* function);
};
CallHandlerInfo* api_call_info_;
};
-
-typedef Object* (*CustomCallGenerator)(CallStubCompiler* compiler,
- Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
- StubCompiler::CheckType check);
-
-
-Object* CompileArrayPushCall(CallStubCompiler* compiler,
- Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
- StubCompiler::CheckType check);
-
-
-Object* CompileArrayPopCall(CallStubCompiler* compiler,
- Object* object,
- JSObject* holder,
- JSFunction* function,
- String* name,
- StubCompiler::CheckType check);
-
-
} } // namespace v8::internal
#endif // V8_STUB_CACHE_H_
SharedFunctionInfo* function_info = function->shared();
if (function_info->HasCustomCallGenerator()) {
- CustomCallGenerator generator =
- ToCData<CustomCallGenerator>(function_info->function_data());
- Object* result = generator(this, object, holder, function, name, check);
+ const int id = function_info->custom_call_generator_id();
+ Object* result =
+ CompileCustomCall(id, object, holder, function, name, check);
// undefined means bail out to regular compiler.
if (!result->IsUndefined()) {
return result;
__ Jump(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}
__ jmp(ic, RelocInfo::CODE_TARGET);
// Return the generated code.
- String* function_name = NULL;
- if (function->shared()->name()->IsString()) {
- function_name = String::cast(function->shared()->name());
- }
- return GetCode(CONSTANT_FUNCTION, function_name);
+ return GetCode(function);
}