Revision: 22093
Author:   [email protected]
Date:     Mon Jun 30 13:35:16 2014 UTC
Log:      Parser: add usage counters for "use asm".

[email protected]
BUG=

Review URL: https://codereview.chromium.org/336863007
http://code.google.com/p/v8/source/detail?r=22093

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/src/ast-value-factory.h
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/parser.h
 /branches/bleeding_edge/test/cctest/test-parsing.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Mon Jun 30 13:16:42 2014 UTC
+++ /branches/bleeding_edge/include/v8.h        Mon Jun 30 13:35:16 2014 UTC
@@ -4134,7 +4134,8 @@
    * list.
    */
   enum UseCounterFeature {
-    kUseAsm = 0
+    kUseAsm = 0,
+    kUseCounterFeatureCount  // This enum value must be last.
   };

   typedef void (*UseCounterCallback)(Isolate* isolate,
=======================================
--- /branches/bleeding_edge/src/ast-value-factory.h Thu Jun 26 11:59:42 2014 UTC +++ /branches/bleeding_edge/src/ast-value-factory.h Mon Jun 30 13:35:16 2014 UTC
@@ -260,6 +260,7 @@
   F(proto, "__proto__") \
   F(prototype, "prototype") \
   F(this, "this") \
+  F(use_asm, "use asm") \
   F(use_strict, "use strict") \
   F(value, "value")

=======================================
--- /branches/bleeding_edge/src/parser.cc       Mon Jun 30 13:25:46 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc       Mon Jun 30 13:35:16 2014 UTC
@@ -783,6 +783,10 @@
   set_allow_generators(FLAG_harmony_generators);
   set_allow_for_of(FLAG_harmony_iteration);
   set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
+  for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
+       ++feature) {
+    use_counts_[feature] = 0;
+  }
 }


@@ -1087,11 +1091,13 @@
       if ((e_stat = stat->AsExpressionStatement()) != NULL &&
           (literal = e_stat->expression()->AsLiteral()) != NULL &&
           literal->raw_value()->IsString()) {
-        // Check "use strict" directive (ES5 14.1).
+ // Check "use strict" directive (ES5 14.1) and "use asm" directive. Only
+        // one can be present.
         if (strict_mode() == SLOPPY &&
             literal->raw_value()->AsString() ==
                 ast_value_factory_->use_strict_string() &&
-            token_loc.end_pos - token_loc.beg_pos == 12) {
+            token_loc.end_pos - token_loc.beg_pos ==
+                ast_value_factory_->use_strict_string()->length() + 2) {
// TODO(mstarzinger): Global strict eval calls, need their own scope // as specified in ES5 10.4.2(3). The correct fix would be to always // add this scope in DoParseProgram(), but that requires adaptations
@@ -1108,6 +1114,13 @@
           scope_->SetStrictMode(STRICT);
           // "use strict" is the only directive for now.
           directive_prologue = false;
+        } else if (literal->raw_value()->AsString() ==
+                       ast_value_factory_->use_asm_string() &&
+                   token_loc.end_pos - token_loc.beg_pos ==
+ ast_value_factory_->use_asm_string()->length() + 2) { + // Store the usage count; The actual use counter on the isolate is
+          // incremented after parsing is done.
+          ++use_counts_[v8::Isolate::kUseAsm];
         }
       } else {
         // End of the directive prologue.
@@ -3897,6 +3910,16 @@
     isolate()->Throw(*result, &location);
   }
 }
+
+
+void Parser::InternalizeUseCounts() {
+  for (int feature = 0; feature < v8::Isolate::kUseCounterFeatureCount;
+       ++feature) {
+    for (int i = 0; i < use_counts_[feature]; ++i) {
+      isolate()->CountUsage(v8::Isolate::UseCounterFeature(feature));
+    }
+  }
+}


// ----------------------------------------------------------------------------
@@ -4840,6 +4863,9 @@
     info()->SetAstValueFactory(ast_value_factory_);
   }
   ast_value_factory_ = NULL;
+
+  InternalizeUseCounts();
+
   return (result != NULL);
 }

=======================================
--- /branches/bleeding_edge/src/parser.h        Thu Jun 26 11:59:42 2014 UTC
+++ /branches/bleeding_edge/src/parser.h        Mon Jun 30 13:35:16 2014 UTC
@@ -798,6 +798,8 @@

   void ThrowPendingError();

+  void InternalizeUseCounts();
+
   Isolate* isolate_;

   Handle<Script> script_;
@@ -818,6 +820,8 @@
   const AstRawString* pending_error_arg_;
   const char* pending_error_char_arg_;
   bool pending_error_is_reference_error_;
+
+  int use_counts_[v8::Isolate::kUseCounterFeatureCount];
 };


=======================================
--- /branches/bleeding_edge/test/cctest/test-parsing.cc Mon Jun 30 13:25:46 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-parsing.cc Mon Jun 30 13:35:16 2014 UTC
@@ -2745,3 +2745,29 @@
     }
   }
 }
+
+namespace {
+
+int* global_use_counts = NULL;
+
+void MockUseCounterCallback(v8::Isolate* isolate,
+                            v8::Isolate::UseCounterFeature feature) {
+  ++global_use_counts[feature];
+}
+
+}
+
+
+TEST(UseAsmUseCount) {
+  i::Isolate* isolate = CcTest::i_isolate();
+  i::HandleScope scope(isolate);
+  LocalContext env;
+  int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
+  global_use_counts = use_counts;
+  CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
+  CompileRun("\"use asm\";\n"
+             "var foo = 1;\n"
+             "\"use asm\";\n"  // Only the first one counts.
+             "function bar() { \"use asm\"; var baz = 1; }");
+  CHECK_EQ(2, use_counts[v8::Isolate::kUseAsm]);
+}

--
--
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/d/optout.

Reply via email to