@ -207,36 +207,33 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
}
}
void InstallIn Cache( Isolate * isolate , int serial_number ,
void CacheFunction ( Isolate * isolate , Handle < Smi > serial_number ,
Handle < JSFunction > function ) {
Handle < JSFunction > function ) {
auto cache = isolate - > function_cache ( ) ;
auto cache = isolate - > function_cache ( ) ;
if ( cache - > length ( ) < = serial_number ) {
auto new_cache = ObjectHashTable : : Put ( cache , serial_number , function ) ;
int new_size ;
isolate - > native_context ( ) - > set_function_cache ( * new_cache ) ;
if ( isolate - > next_serial_number ( ) < 50 ) {
}
new_size = 100 ;
} else {
new_size = 3 * isolate - > next_serial_number ( ) / 2 ;
void UncacheFunction ( Isolate * isolate , Handle < Smi > serial_number ) {
}
auto cache = isolate - > function_cache ( ) ;
cache = FixedArray : : CopySize ( cache , new_size ) ;
bool was_present = false ;
isolate - > native_context ( ) - > set_function_cache ( * cache ) ;
auto new_cache = ObjectHashTable : : Remove ( cache , serial_number , & was_present ) ;
}
DCHECK ( was_present ) ;
cache - > set ( serial_number , * function ) ;
isolate - > native_context ( ) - > set_function_cache ( * new_cache ) ;
}
}
MaybeHandle < JSFunction > InstantiateFunction ( Isolate * isolate ,
MaybeHandle < JSFunction > InstantiateFunction ( Isolate * isolate ,
Handle < FunctionTemplateInfo > data ,
Handle < FunctionTemplateInfo > data ,
Handle < Name > name ) {
Handle < Name > name ) {
int serial_number = Smi : : cast ( data - > serial_number ( ) ) - > value ( ) ;
auto serial_number = handle ( Smi : : cast ( data - > serial_number ( ) ) , isolate ) ;
// Probe cache.
// Probe cache.
if ( ! data - > do_not_cache ( ) ) {
if ( ! data - > do_not_cache ( ) ) {
auto cache = isolate - > function_cache ( ) ;
auto cache = isolate - > function_cache ( ) ;
// Fast case: see if the function has already been instantiated
Object * element = cache - > Lookup ( serial_number ) ;
if ( serial_number < cache - > length ( ) ) {
if ( element - > IsJSFunction ( ) ) {
Handle < Object > element = FixedArray : : get ( cache , serial_number ) ;
return handle ( JSFunction : : cast ( element ) , isolate ) ;
if ( element - > IsJSFunction ( ) ) {
return Handle < JSFunction > : : cast ( element ) ;
}
}
}
}
}
// Enter a new scope. Recursion could otherwise create a lot of handles.
// Enter a new scope. Recursion could otherwise create a lot of handles.
@ -279,15 +276,14 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
function - > shared ( ) - > set_name ( * name ) ;
function - > shared ( ) - > set_name ( * name ) ;
}
}
if ( ! data - > do_not_cache ( ) ) {
if ( ! data - > do_not_cache ( ) ) {
// Cache the function to limit recursion .
// Cache the function.
InstallIn Cache( isolate , serial_number , function ) ;
CacheFunction ( isolate , serial_number , function ) ;
}
}
auto result = ConfigureInstance ( isolate , function , data ) ;
auto result = ConfigureInstance ( isolate , function , data ) ;
if ( result . is_null ( ) ) {
if ( result . is_null ( ) ) {
// u ncache on error.
// U ncache on error.
if ( ! data - > do_not_cache ( ) ) {
if ( ! data - > do_not_cache ( ) ) {
auto cache = isolate - > function_cache ( ) ;
UncacheFunction ( isolate , serial_number ) ;
cache - > set ( serial_number , isolate - > heap ( ) - > undefined_value ( ) ) ;
}
}
return MaybeHandle < JSFunction > ( ) ;
return MaybeHandle < JSFunction > ( ) ;
}
}