Put object templates of the i18n extension on the heap object.

Using function local statics doesn't work, as we need the templates per
isolate.

I'm not #ifdef'ing the definitions out, because kEmptyStringRootIndex
changes depending on whether the two additional slots are present or
not.

BUG=v8:2745
R=mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15888 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
jochen@chromium.org 2013-07-25 16:01:02 +00:00
parent cc9398cd42
commit 0826f85a02
4 changed files with 27 additions and 22 deletions

View File

@ -5399,7 +5399,7 @@ class Internals {
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
static const int kFalseValueRootIndex = 9;
static const int kEmptyStringRootIndex = 132;
static const int kEmptyStringRootIndex = 134;
static const int kNodeClassIdOffset = 1 * kApiPointerSize;
static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;

View File

@ -142,40 +142,34 @@ void Utils::AsciiToUChar(const char* source,
// static
// Chrome Linux doesn't like static initializers in class, so we create
// template on demand.
v8::Local<v8::ObjectTemplate> Utils::GetTemplate(v8::Isolate* isolate) {
static v8::Persistent<v8::ObjectTemplate> icu_template;
if (icu_template.IsEmpty()) {
i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate);
if (internal->heap()->i18n_template_one() ==
internal->heap()->the_hole_value()) {
v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New());
// Set aside internal field for ICU class.
raw_template->SetInternalFieldCount(1);
icu_template.Reset(isolate, raw_template);
internal->heap()
->SetI18nTemplateOne(*v8::Utils::OpenHandle(*raw_template));
}
return v8::Local<v8::ObjectTemplate>::New(isolate, icu_template);
return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(
internal->factory()->i18n_template_one()));
}
// static
// Chrome Linux doesn't like static initializers in class, so we create
// template on demand. This one has 2 internal fields.
v8::Local<v8::ObjectTemplate> Utils::GetTemplate2(v8::Isolate* isolate) {
static v8::Persistent<v8::ObjectTemplate> icu_template_2;
if (icu_template_2.IsEmpty()) {
i::Isolate* internal = reinterpret_cast<i::Isolate*>(isolate);
if (internal->heap()->i18n_template_two() ==
internal->heap()->the_hole_value()) {
v8::Local<v8::ObjectTemplate> raw_template(v8::ObjectTemplate::New());
// Set aside internal field for ICU class and additional data.
raw_template->SetInternalFieldCount(2);
icu_template_2.Reset(isolate, raw_template);
internal->heap()
->SetI18nTemplateTwo(*v8::Utils::OpenHandle(*raw_template));
}
return v8::Local<v8::ObjectTemplate>::New(isolate, icu_template_2);
return v8::Utils::ToLocal(i::Handle<i::ObjectTemplateInfo>::cast(
internal->factory()->i18n_template_two()));
}
} // namespace v8_i18n

View File

@ -3223,6 +3223,9 @@ bool Heap::CreateInitialObjects() {
}
set_observed_symbol(Symbol::cast(obj));
set_i18n_template_one(the_hole_value());
set_i18n_template_two(the_hole_value());
// Handling of script id generation is in Factory::NewScript.
set_last_script_id(Smi::FromInt(v8::Script::kNoScriptId));

View File

@ -188,7 +188,9 @@ namespace internal {
V(Symbol, frozen_symbol, FrozenSymbol) \
V(SeededNumberDictionary, empty_slow_element_dictionary, \
EmptySlowElementDictionary) \
V(Symbol, observed_symbol, ObservedSymbol)
V(Symbol, observed_symbol, ObservedSymbol) \
V(HeapObject, i18n_template_one, I18nTemplateOne) \
V(HeapObject, i18n_template_two, I18nTemplateTwo)
#define ROOT_LIST(V) \
STRONG_ROOT_LIST(V) \
@ -1295,6 +1297,12 @@ class Heap {
ASSERT((callback == NULL) ^ (global_gc_epilogue_callback_ == NULL));
global_gc_epilogue_callback_ = callback;
}
void SetI18nTemplateOne(ObjectTemplateInfo* tmpl) {
set_i18n_template_one(tmpl);
}
void SetI18nTemplateTwo(ObjectTemplateInfo* tmpl) {
set_i18n_template_two(tmpl);
}
// Heap root getters. We have versions with and without type::cast() here.
// You can't use type::cast during GC because the assert fails.