Commit 49c1e711 authored by jochen's avatar jochen Committed by Commit bot

[api] Don't store the serial number of templates in handles

We know it's a postive integer

BUG=
R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/1739753004

Cr-Commit-Position: refs/heads/master@{#34327}
parent bd39edcd
...@@ -266,17 +266,17 @@ MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj, ...@@ -266,17 +266,17 @@ MaybeHandle<JSObject> ConfigureInstance(Isolate* isolate, Handle<JSObject> obj,
return obj; return obj;
} }
void CacheTemplateInstantiation(Isolate* isolate, Handle<Smi> serial_number, void CacheTemplateInstantiation(Isolate* isolate, uint32_t serial_number,
Handle<JSObject> object) { Handle<JSObject> object) {
auto cache = isolate->template_instantiations_cache(); auto cache = isolate->template_instantiations_cache();
auto new_cache = UnseededNumberDictionary::AtNumberPut( auto new_cache =
cache, static_cast<uint32_t>(serial_number->value()), object); UnseededNumberDictionary::AtNumberPut(cache, serial_number, object);
isolate->native_context()->set_template_instantiations_cache(*new_cache); isolate->native_context()->set_template_instantiations_cache(*new_cache);
} }
void UncacheTemplateInstantiation(Isolate* isolate, Handle<Smi> serial_number) { void UncacheTemplateInstantiation(Isolate* isolate, uint32_t serial_number) {
auto cache = isolate->template_instantiations_cache(); auto cache = isolate->template_instantiations_cache();
int entry = cache->FindEntry(static_cast<uint32_t>(serial_number->value())); int entry = cache->FindEntry(serial_number);
DCHECK(entry != UnseededNumberDictionary::kNotFound); DCHECK(entry != UnseededNumberDictionary::kNotFound);
Handle<Object> result = Handle<Object> result =
UnseededNumberDictionary::DeleteProperty(cache, entry); UnseededNumberDictionary::DeleteProperty(cache, entry);
...@@ -291,11 +291,12 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, ...@@ -291,11 +291,12 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
bool is_hidden_prototype) { bool is_hidden_prototype) {
// Fast path. // Fast path.
Handle<JSObject> result; Handle<JSObject> result;
auto serial_number = handle(Smi::cast(info->serial_number()), isolate); uint32_t serial_number =
if (serial_number->value()) { static_cast<uint32_t>(Smi::cast(info->serial_number())->value());
if (serial_number) {
// Probe cache. // Probe cache.
auto cache = isolate->template_instantiations_cache(); auto cache = isolate->template_instantiations_cache();
int entry = cache->FindEntry(static_cast<uint32_t>(serial_number->value())); int entry = cache->FindEntry(serial_number);
if (entry != UnseededNumberDictionary::kNotFound) { if (entry != UnseededNumberDictionary::kNotFound) {
Object* boilerplate = cache->ValueAt(entry); Object* boilerplate = cache->ValueAt(entry);
result = handle(JSObject::cast(boilerplate), isolate); result = handle(JSObject::cast(boilerplate), isolate);
...@@ -323,7 +324,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, ...@@ -323,7 +324,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
// TODO(dcarney): is this necessary? // TODO(dcarney): is this necessary?
JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject"); JSObject::MigrateSlowToFast(result, 0, "ApiNatives::InstantiateObject");
if (serial_number->value()) { if (serial_number) {
CacheTemplateInstantiation(isolate, serial_number, result); CacheTemplateInstantiation(isolate, serial_number, result);
ASSIGN_RETURN_ON_EXCEPTION( ASSIGN_RETURN_ON_EXCEPTION(
isolate, result, JSObject::DeepCopyApiBoilerplate(result), JSObject); isolate, result, JSObject::DeepCopyApiBoilerplate(result), JSObject);
...@@ -335,11 +336,12 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate, ...@@ -335,11 +336,12 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
Handle<FunctionTemplateInfo> data, Handle<FunctionTemplateInfo> data,
Handle<Name> name) { Handle<Name> name) {
auto serial_number = handle(Smi::cast(data->serial_number()), isolate); uint32_t serial_number =
if (serial_number->value()) { static_cast<uint32_t>(Smi::cast(data->serial_number())->value());
if (serial_number) {
// Probe cache. // Probe cache.
auto cache = isolate->template_instantiations_cache(); auto cache = isolate->template_instantiations_cache();
int entry = cache->FindEntry(static_cast<uint32_t>(serial_number->value())); int entry = cache->FindEntry(serial_number);
if (entry != UnseededNumberDictionary::kNotFound) { if (entry != UnseededNumberDictionary::kNotFound) {
Object* element = cache->ValueAt(entry); Object* element = cache->ValueAt(entry);
return handle(JSFunction::cast(element), isolate); return handle(JSFunction::cast(element), isolate);
...@@ -385,7 +387,7 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, ...@@ -385,7 +387,7 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
if (!name.is_null() && name->IsString()) { if (!name.is_null() && name->IsString()) {
function->shared()->set_name(*name); function->shared()->set_name(*name);
} }
if (serial_number->value()) { if (serial_number) {
// Cache the function. // Cache the function.
CacheTemplateInstantiation(isolate, serial_number, function); CacheTemplateInstantiation(isolate, serial_number, function);
} }
...@@ -393,7 +395,7 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate, ...@@ -393,7 +395,7 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
ConfigureInstance(isolate, function, data, data->hidden_prototype()); ConfigureInstance(isolate, function, data, data->hidden_prototype());
if (result.is_null()) { if (result.is_null()) {
// Uncache on error. // Uncache on error.
if (serial_number->value()) { if (serial_number) {
UncacheTemplateInstantiation(isolate, serial_number); UncacheTemplateInstantiation(isolate, serial_number);
} }
return MaybeHandle<JSFunction>(); return MaybeHandle<JSFunction>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment