[strong] Introduce strong bit
authorrossberg <rossberg@chromium.org>
Wed, 13 May 2015 13:31:19 +0000 (06:31 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 13 May 2015 13:31:12 +0000 (13:31 +0000)
Only set on strong functions so far to test basic operation.

R=dslomov@chromium.org
BUG=v8:3956
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#28396}

src/bootstrapper.cc
src/macros.py
src/objects-inl.h
src/objects.h
src/runtime/runtime-object.cc
src/runtime/runtime.h
test/mjsunit/strong/objects.js [new file with mode: 0644]

index f49e340..f2e5196 100644 (file)
@@ -705,7 +705,7 @@ Handle<Map> Genesis::CreateStrongFunctionMap(
   map->set_function_with_prototype(is_constructor);
   Map::SetPrototype(map, empty_function);
   map->set_is_extensible(is_constructor);
-  // TODO(rossberg): mark strong
+  map->set_is_strong(true);
   return map;
 }
 
index 9fd5442..9c166f6 100644 (file)
@@ -116,6 +116,7 @@ macro IS_GENERATOR(arg)         = (%_ClassOf(arg) === 'Generator');
 macro IS_SET_ITERATOR(arg)      = (%_ClassOf(arg) === 'Set Iterator');
 macro IS_MAP_ITERATOR(arg)      = (%_ClassOf(arg) === 'Map Iterator');
 macro IS_UNDETECTABLE(arg)      = (%_IsUndetectableObject(arg));
+macro IS_STRONG(arg)            = (%IsStrong(arg));
 
 # Macro for ECMAScript 5 queries of the type:
 # "Type(O) is object."
index 026166f..fc43120 100644 (file)
@@ -4715,6 +4715,16 @@ bool Map::is_migration_target() {
 }
 
 
+void Map::set_is_strong(bool value) {
+  set_bit_field3(IsStrong::update(bit_field3(), value));
+}
+
+
+bool Map::is_strong() {
+  return IsStrong::decode(bit_field3());
+}
+
+
 void Map::set_counter(int value) {
   set_bit_field3(Counter::update(bit_field3(), value));
 }
index 7c9b4f8..0aefb4c 100644 (file)
@@ -5901,7 +5901,8 @@ class Map: public HeapObject {
   class Deprecated : public BitField<bool, 23, 1> {};
   class IsUnstable : public BitField<bool, 24, 1> {};
   class IsMigrationTarget : public BitField<bool, 25, 1> {};
-  // Bits 26 and 27 are free.
+  class IsStrong : public BitField<bool, 26, 1> {};
+  // Bit 27 is free.
 
   // Keep this bit field at the very end for better code in
   // Builtins::kJSConstructStubGeneric stub.
@@ -5979,6 +5980,8 @@ class Map: public HeapObject {
     return ((1 << kIsObserved) & bit_field()) != 0;
   }
 
+  inline void set_is_strong(bool value);
+  inline bool is_strong();
   inline void set_is_extensible(bool value);
   inline bool is_extensible();
   inline void set_is_prototype_map(bool value);
index ca35c10..e4478b7 100644 (file)
@@ -1518,6 +1518,15 @@ RUNTIME_FUNCTION(Runtime_IsSpecObject) {
 }
 
 
+RUNTIME_FUNCTION(Runtime_IsStrong) {
+  SealHandleScope shs(isolate);
+  DCHECK(args.length() == 1);
+  CONVERT_ARG_CHECKED(Object, obj, 0);
+  return isolate->heap()->ToBoolean(obj->IsJSReceiver() &&
+                                    JSReceiver::cast(obj)->map()->is_strong());
+}
+
+
 RUNTIME_FUNCTION(Runtime_ClassOf) {
   SealHandleScope shs(isolate);
   DCHECK(args.length() == 1);
index 809ce66..bd37a68 100644 (file)
@@ -452,6 +452,7 @@ namespace internal {
   F(IsObject, 1, 1)                                  \
   F(IsUndetectableObject, 1, 1)                      \
   F(IsSpecObject, 1, 1)                              \
+  F(IsStrong, 1, 1)                                  \
   F(ClassOf, 1, 1)                                   \
   F(DefineGetterPropertyUnchecked, 4, 1)             \
   F(DefineSetterPropertyUnchecked, 4, 1)
diff --git a/test/mjsunit/strong/objects.js b/test/mjsunit/strong/objects.js
new file mode 100644 (file)
index 0000000..4654606
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --strong-mode --allow-natives-syntax
+
+'use strong';
+
+function f() {}
+assertTrue(%IsStrong(f));