Reviewers: Kevin Millikin, Steven,

Description:
Improve Hydrogen code for accessing undefined/null/Infinity.

In some special (but probably very common) cases we can do better than loading
from a global cell for these global properties by emitting the corresponding
constant directly. This opens up opportunities for further improvements, coming
in a separate CL...

Please review this at http://codereview.chromium.org/7992002/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/factory.h
  M     src/factory.cc
  M     src/heap.h
  M     src/heap.cc
  M     src/hydrogen.cc


Index: src/factory.cc
===================================================================
--- src/factory.cc      (revision 9392)
+++ src/factory.cc      (working copy)
@@ -1315,4 +1315,13 @@
 }


+Handle<Object> Factory::GlobalConstantFor(Handle<String> name) {
+  Heap* h = isolate()->heap();
+  if (name->Equals(h->undefined_symbol())) return undefined_value();
+  if (name->Equals(h->nan_symbol())) return nan_value();
+  if (name->Equals(h->infinity_symbol())) return infinity_value();
+  return Handle<Object>::null();
+}
+
+
 } }  // namespace v8::internal
Index: src/factory.h
===================================================================
--- src/factory.h       (revision 9392)
+++ src/factory.h       (working copy)
@@ -444,6 +444,10 @@
                              JSRegExp::Flags flags,
                              int capture_count);

+  // Returns the value for a known global constant like 'undefined' or
+  // a null handle when the given name is unknown.
+  Handle<Object> GlobalConstantFor(Handle<String> name);
+
  private:
   Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }

Index: src/heap.cc
===================================================================
--- src/heap.cc (revision 9392)
+++ src/heap.cc (working copy)
@@ -2192,6 +2192,11 @@
   }
   set_nan_value(obj);

+  { MaybeObject* maybe_obj = AllocateHeapNumber(V8_INFINITY, TENURED);
+    if (!maybe_obj->ToObject(&obj)) return false;
+  }
+  set_infinity_value(obj);
+
   { MaybeObject* maybe_obj = Allocate(oddball_map(), OLD_POINTER_SPACE);
     if (!maybe_obj->ToObject(&obj)) return false;
   }
Index: src/heap.h
===================================================================
--- src/heap.h  (revision 9392)
+++ src/heap.h  (working copy)
@@ -126,6 +126,7 @@
V(Map, message_object_map, JSMessageObjectMap) \ V(Map, foreign_map, ForeignMap) \ V(Object, nan_value, NanValue) \ + V(Object, infinity_value, InfinityValue) \ V(Object, minus_zero_value, MinusZeroValue) \ V(Map, neander_map, NeanderMap) \ V(JSObject, message_listeners, MessageListeners) \
@@ -229,7 +230,8 @@
   V(closure_symbol, "(closure)")                                         \
   V(use_strict, "use strict")                                            \
   V(dot_symbol, ".")                                                     \
-  V(anonymous_function_symbol, "(anonymous function)")
+  V(anonymous_function_symbol, "(anonymous function)")                   \
+  V(infinity_symbol, "Infinity")

 // Forward declarations.
 class GCTracer;
Index: src/hydrogen.cc
===================================================================
--- src/hydrogen.cc     (revision 9392)
+++ src/hydrogen.cc     (working copy)
@@ -3146,6 +3146,16 @@
   }
   switch (variable->location()) {
     case Variable::UNALLOCATED: {
+ // Handle known global constants like 'undefined' specially to avoid a
+      // load from a global cell for them.
+      Handle<Object> constant_value =
+          isolate()->factory()->GlobalConstantFor(variable->name());
+      if (!constant_value.is_null()) {
+        HConstant* instr =
+ new(zone()) HConstant(constant_value, Representation::Tagged());
+        return ast_context()->ReturnInstruction(instr, expr->id());
+      }
+
       LookupResult lookup;
       GlobalPropertyAccess type =
           LookupGlobalProperty(variable, &lookup, false);


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to