Reviewers: danno,
Description:
Reland "Compilation type and state allocate an unnecessary Smi on
v8::Script"
(r15940).
It turns out that this change is not related to the test failures.
[email protected]
Please review this at https://codereview.chromium.org/21256003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/accessors.cc
M src/compiler.cc
M src/factory.cc
M src/isolate.cc
M src/liveedit.cc
M src/objects-inl.h
M src/objects-printer.cc
M src/objects.h
M src/runtime.cc
Index: src/accessors.cc
diff --git a/src/accessors.cc b/src/accessors.cc
index
51db3615c382f38d787333b98ac753bf9e7f83d9..a43eb78b8702d57ca504e734a38e1bc635582bec
100644
--- a/src/accessors.cc
+++ b/src/accessors.cc
@@ -292,7 +292,7 @@ const AccessorDescriptor Accessors::ScriptType = {
MaybeObject* Accessors::ScriptGetCompilationType(Object* object, void*) {
Object* script = JSValue::cast(object)->value();
- return Script::cast(script)->compilation_type();
+ return Smi::FromInt(Script::cast(script)->compilation_type());
}
@@ -388,8 +388,7 @@ MaybeObject*
Accessors::ScriptGetEvalFromScriptPosition(Object* object, void*) {
Handle<Script> script(raw_script);
// If this is not a script compiled through eval there is no eval
position.
- int compilation_type = Smi::cast(script->compilation_type())->value();
- if (compilation_type != Script::COMPILATION_TYPE_EVAL) {
+ if (script->compilation_type() != Script::COMPILATION_TYPE_EVAL) {
return script->GetHeap()->undefined_value();
}
Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index
b5979bcae80ab2b7b7fb5358f50e748cba79ba6b..4cac73f7b69b2e1543d0d557018570ead6b808f9
100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -558,8 +558,7 @@ static Handle<SharedFunctionInfo>
MakeFunctionInfo(CompilationInfo* info) {
#ifdef ENABLE_DEBUGGER_SUPPORT
if (info->is_eval()) {
- Script::CompilationType compilation_type =
Script::COMPILATION_TYPE_EVAL;
- script->set_compilation_type(Smi::FromInt(compilation_type));
+ script->set_compilation_type(Script::COMPILATION_TYPE_EVAL);
// For eval scripts add information on the function from which eval was
// called.
if (info->is_eval()) {
@@ -650,8 +649,7 @@ static Handle<SharedFunctionInfo>
MakeFunctionInfo(CompilationInfo* info) {
// the instances of the function.
SetExpectedNofPropertiesFromEstimate(result,
lit->expected_property_count());
- script->set_compilation_state(
- Smi::FromInt(Script::COMPILATION_STATE_COMPILED));
+ script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
#ifdef ENABLE_DEBUGGER_SUPPORT
// Notify debugger
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index
b135a9c6705bb8866ae0d66b3c1f34ff79d526d5..c5a1fddb88b413c843f7ca051a421026b035537c
100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -453,13 +453,11 @@ Handle<Script> Factory::NewScript(Handle<String>
source) {
script->set_data(heap->undefined_value());
script->set_context_data(heap->undefined_value());
script->set_type(Smi::FromInt(Script::TYPE_NORMAL));
-
script->set_compilation_type(Smi::FromInt(Script::COMPILATION_TYPE_HOST));
- script->set_compilation_state(
- Smi::FromInt(Script::COMPILATION_STATE_INITIAL));
script->set_wrapper(*wrapper);
script->set_line_ends(heap->undefined_value());
script->set_eval_from_shared(heap->undefined_value());
script->set_eval_from_instructions_offset(Smi::FromInt(0));
+ script->set_flags(Smi::FromInt(0));
return script;
}
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index
bcd48945f2816b95b7c542cc9477b37e99dbe40c..61f1e2dcfa5627e1cf872c911f1cef77aa315dd5
100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -816,9 +816,9 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
}
if (options & StackTrace::kIsEval) {
- int type = Smi::cast(script->compilation_type())->value();
- Handle<Object> is_eval = (type == Script::COMPILATION_TYPE_EVAL) ?
- factory()->true_value() : factory()->false_value();
+ Handle<Object> is_eval =
+ script->compilation_type() == Script::COMPILATION_TYPE_EVAL ?
+ factory()->true_value() : factory()->false_value();
CHECK_NOT_EMPTY_HANDLE(this,
JSObject::SetLocalPropertyIgnoreAttributes(
stack_frame, eval_key, is_eval, NONE));
Index: src/liveedit.cc
diff --git a/src/liveedit.cc b/src/liveedit.cc
index
bab2e101bc22d7a6ca5e39082ff0cbe0eac4155a..859cf2b94f34bd61e28afb185eb40f6c04d2f8bd
100644
--- a/src/liveedit.cc
+++ b/src/liveedit.cc
@@ -1557,11 +1557,14 @@ static Handle<Script>
CreateScriptCopy(Handle<Script> original) {
copy->set_data(original->data());
copy->set_type(original->type());
copy->set_context_data(original->context_data());
- copy->set_compilation_type(original->compilation_type());
copy->set_eval_from_shared(original->eval_from_shared());
copy->set_eval_from_instructions_offset(
original->eval_from_instructions_offset());
+ // Copy all the flags, but clear compilation state.
+ copy->set_flags(original->flags());
+ copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL);
+
return copy;
}
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index
3189d840304c7cbb5be807cc9b47c8ef470a9372..ef30496963d9741d9c0a277e392a0134a10f3728
100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -4482,12 +4482,29 @@ ACCESSORS(Script, data, Object, kDataOffset)
ACCESSORS(Script, context_data, Object, kContextOffset)
ACCESSORS(Script, wrapper, Foreign, kWrapperOffset)
ACCESSORS_TO_SMI(Script, type, kTypeOffset)
-ACCESSORS_TO_SMI(Script, compilation_type, kCompilationTypeOffset)
-ACCESSORS_TO_SMI(Script, compilation_state, kCompilationStateOffset)
ACCESSORS(Script, line_ends, Object, kLineEndsOffset)
ACCESSORS(Script, eval_from_shared, Object, kEvalFromSharedOffset)
ACCESSORS_TO_SMI(Script, eval_from_instructions_offset,
kEvalFrominstructionsOffsetOffset)
+ACCESSORS_TO_SMI(Script, flags, kFlagsOffset)
+
+Script::CompilationType Script::compilation_type() {
+ return BooleanBit::get(flags(), kCompilationTypeBit) ?
+ COMPILATION_TYPE_EVAL : COMPILATION_TYPE_HOST;
+}
+void Script::set_compilation_type(CompilationType type) {
+ set_flags(BooleanBit::set(flags(), kCompilationTypeBit,
+ type == COMPILATION_TYPE_EVAL));
+}
+Script::CompilationState Script::compilation_state() {
+ return BooleanBit::get(flags(), kCompilationStateBit) ?
+ COMPILATION_STATE_COMPILED : COMPILATION_STATE_INITIAL;
+}
+void Script::set_compilation_state(CompilationState state) {
+ set_flags(BooleanBit::set(flags(), kCompilationStateBit,
+ state == COMPILATION_STATE_COMPILED));
+}
+
#ifdef ENABLE_DEBUGGER_SUPPORT
ACCESSORS(DebugInfo, shared, SharedFunctionInfo, kSharedFunctionInfoIndex)
Index: src/objects-printer.cc
diff --git a/src/objects-printer.cc b/src/objects-printer.cc
index
2327cbae8a3daa1c7be34a68a28add679067dc97..6b2a3f0d4f534cbf5fe314e2f94e4c8ef6be3d0b
100644
--- a/src/objects-printer.cc
+++ b/src/objects-printer.cc
@@ -1202,8 +1202,7 @@ void Script::ScriptPrint(FILE* out) {
context_data()->ShortPrint(out);
PrintF(out, "\n - wrapper: ");
wrapper()->ShortPrint(out);
- PrintF(out, "\n - compilation type: ");
- compilation_type()->ShortPrint(out);
+ PrintF(out, "\n - compilation type: %d", compilation_type());
PrintF(out, "\n - line ends: ");
line_ends()->ShortPrint(out);
PrintF(out, "\n - eval from shared: ");
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index
36611ee077710cdf4efebbc3beb8afe53bf17c52..388187445fe524bdb5aa7d6e31f0c074b51abe34
100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -5849,12 +5849,6 @@ class Script: public Struct {
// [type]: the script type.
DECL_ACCESSORS(type, Smi)
- // [compilation]: how the the script was compiled.
- DECL_ACCESSORS(compilation_type, Smi)
-
- // [is_compiled]: determines whether the script has already been
compiled.
- DECL_ACCESSORS(compilation_state, Smi)
-
// [line_ends]: FixedArray of line ends positions.
DECL_ACCESSORS(line_ends, Object)
@@ -5866,6 +5860,19 @@ class Script: public Struct {
// function from which eval was called where eval was called.
DECL_ACCESSORS(eval_from_instructions_offset, Smi)
+ // [flags]: Holds an exciting bitfield.
+ DECL_ACCESSORS(flags, Smi)
+
+ // [compilation_type]: how the the script was compiled. Encoded in the
+ // 'flags' field.
+ inline CompilationType compilation_type();
+ inline void set_compilation_type(CompilationType type);
+
+ // [compilation_state]: determines whether the script has already been
+ // compiled. Encoded in the 'flags' field.
+ inline CompilationState compilation_state();
+ inline void set_compilation_state(CompilationState state);
+
static inline Script* cast(Object* obj);
// If script source is an external string, check that the underlying
@@ -5884,17 +5891,20 @@ class Script: public Struct {
static const int kContextOffset = kDataOffset + kPointerSize;
static const int kWrapperOffset = kContextOffset + kPointerSize;
static const int kTypeOffset = kWrapperOffset + kPointerSize;
- static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
- static const int kCompilationStateOffset =
- kCompilationTypeOffset + kPointerSize;
- static const int kLineEndsOffset = kCompilationStateOffset +
kPointerSize;
+ static const int kLineEndsOffset = kTypeOffset + kPointerSize;
static const int kIdOffset = kLineEndsOffset + kPointerSize;
static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
static const int kEvalFrominstructionsOffsetOffset =
kEvalFromSharedOffset + kPointerSize;
- static const int kSize = kEvalFrominstructionsOffsetOffset +
kPointerSize;
+ static const int kFlagsOffset =
+ kEvalFrominstructionsOffsetOffset + kPointerSize;
+ static const int kSize = kFlagsOffset + kPointerSize;
private:
+ // Bit positions in the flags field.
+ static const int kCompilationTypeBit = 0;
+ static const int kCompilationStateBit = 1;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
};
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
4b20bcd5f2e2faba379ce17d26eb767ab454b33a..ed3527fa9202cb9977101725598cec30b3af1bba
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -12887,7 +12887,7 @@ RUNTIME_FUNCTION(MaybeObject*,
Runtime_DebugSetScriptSource) {
RUNTIME_ASSERT(script_wrapper->value()->IsScript());
Handle<Script> script(Script::cast(script_wrapper->value()));
- int compilation_state = Smi::cast(script->compilation_state())->value();
+ int compilation_state = script->compilation_state();
RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL);
script->set_source(*source);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.