Remove JAVASCRIPT_PROFILER define
[WebKit-https.git] / JavaScriptCore / VM / Machine.cpp
index 0865a98..177a748 100644 (file)
@@ -437,14 +437,12 @@ static NEVER_INLINE bool isNotObject(ExecState* exec, const Instruction*, CodeBl
     return true;
 }
 
-#if JAVASCRIPT_PROFILING
-static NEVER_INLINE JSValue* callEval(ExecState* exec, JSObject* evalFunction, JSObject* thisObj, ScopeChainNode* scopeChain, RegisterFile* registerFile, Register* r, int argv, int argc, JSValue*& exceptionValue)
-{
-    Profiler::profiler()->willExecute(exec, evalFunction);
-#else
 static NEVER_INLINE JSValue* callEval(ExecState* exec, JSObject* thisObj, ScopeChainNode* scopeChain, RegisterFile* registerFile, Register* r, int argv, int argc, JSValue*& exceptionValue)
 {
-#endif
+    Profiler** profiler = Profiler::enabledProfilerReference();
+    JSObject* evalFunction = scopeChain->globalObject()->evalFunction();
+    if (*profiler)
+        (*profiler)->willExecute(exec, evalFunction);
 
     JSValue* x = argc >= 2 ? r[argv + 1].u.jsValue : jsUndefined();
     
@@ -468,15 +466,12 @@ static NEVER_INLINE JSValue* callEval(ExecState* exec, JSObject* thisObj, ScopeC
         return 0;
     }
 
-#if JAVASCRIPT_PROFILING
     JSValue* result = machine().execute(evalNode.get(), exec, thisObj, registerFile, r - (*registerFile->basePointer()) + argv + argc, scopeChain, &exceptionValue);
 
-    Profiler::profiler()->didExecute(exec, evalFunction);
+    if ((*profiler))
+        (*profiler)->didExecute(exec, evalFunction);
 
     return result;
-#else
-    return machine().execute(evalNode.get(), exec, thisObj, registerFile, r - (*registerFile->basePointer()) + argv + argc, scopeChain, &exceptionValue);
-#endif
 }
 
 Machine& machine()
@@ -606,9 +601,8 @@ NEVER_INLINE bool Machine::unwindCallFrame(ExecState* exec, JSValue* exceptionVa
     exec->m_callFrameOffset = callerRegisterOffset - codeBlock->numLocals - CallFrameHeaderSize;
     vPC = callFrame[ReturnVPC].u.vPC;
 
-#if JAVASCRIPT_PROFILING
-    Profiler::profiler()->didExecute(exec, callFrame[Callee].u.jsObject);
-#endif
+    if (Profiler* profiler = *Profiler::enabledProfilerReference())
+        profiler->didExecute(exec, callFrame[Callee].u.jsObject);
     return true;
 }
 
@@ -657,10 +651,6 @@ JSValue* Machine::execute(ProgramNode* programNode, ExecState* exec, ScopeChainN
         return 0;
     }
 
-#if JAVASCRIPT_PROFILING
-    Profiler::profiler()->willExecute(exec, programNode->sourceURL(), programNode->lineNo());
-#endif
-
     RegisterFile* registerFile = registerFileStack->pushGlobalRegisterFile();
     ASSERT(registerFile->numGlobalSlots());
     CodeBlock* codeBlock = &programNode->code(scopeChain, !registerFileStack->inImplicitCall());
@@ -673,7 +663,11 @@ JSValue* Machine::execute(ProgramNode* programNode, ExecState* exec, ScopeChainN
     
     if (codeBlock->needsFullScopeChain)
         scopeChain = scopeChain->copy();
-    
+
+    Profiler** profiler = Profiler::enabledProfilerReference();
+    if (*profiler)
+        (*profiler)->willExecute(exec, programNode->sourceURL(), programNode->lineNo());
+
     ExecState newExec(exec, this, registerFile, scopeChain, -1);
 
     m_reentryDepth++;
@@ -682,9 +676,8 @@ JSValue* Machine::execute(ProgramNode* programNode, ExecState* exec, ScopeChainN
 
     registerFileStack->popGlobalRegisterFile();
 
-#if JAVASCRIPT_PROFILING
-    Profiler::profiler()->didExecute(exec, programNode->sourceURL(), programNode->lineNo());
-#endif
+    if (*profiler)
+        (*profiler)->didExecute(exec, programNode->sourceURL(), programNode->lineNo());
 
     return result;
 }
@@ -696,10 +689,6 @@ JSValue* Machine::execute(FunctionBodyNode* functionBodyNode, ExecState* exec, F
         return 0;
     }
 
-#if JAVASCRIPT_PROFILING
-    Profiler::profiler()->willExecute(exec, function);
-#endif
-
     RegisterFile* registerFile = registerFileStack->current();
 
     int argv = CallFrameHeaderSize;
@@ -737,11 +726,18 @@ JSValue* Machine::execute(FunctionBodyNode* functionBodyNode, ExecState* exec, F
     scopeChain = scopeChainForCall(functionBodyNode, newCodeBlock, scopeChain, registerBase, r);            
 
     ExecState newExec(exec, this, registerFile, scopeChain, callFrameOffset);
+    
+    Profiler** profiler = Profiler::enabledProfilerReference();
+    if (*profiler)
+        (*profiler)->willExecute(exec, function);
 
     m_reentryDepth++;
     JSValue* result = privateExecute(Normal, &newExec, registerFile, r, scopeChain, newCodeBlock, exception);
     m_reentryDepth--;
 
+    if (*profiler)
+        (*profiler)->didExecute(exec, function);
+
     registerFile->shrink(oldSize);
     return result;
 }
@@ -753,10 +749,6 @@ JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj
         return 0;
     }
 
-#if JAVASCRIPT_PROFILING
-    Profiler::profiler()->willExecute(exec, evalNode->sourceURL(), evalNode->lineNo());
-#endif
-
     EvalCodeBlock* codeBlock = &evalNode->code(scopeChain);
     
     JSVariableObject* variableObject;
@@ -797,6 +789,10 @@ JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj
     if (codeBlock->needsFullScopeChain)
         scopeChain = scopeChain->copy();
 
+    Profiler** profiler = Profiler::enabledProfilerReference();
+    if (*profiler)
+        (*profiler)->willExecute(exec, evalNode->sourceURL(), evalNode->lineNo());
+
     ExecState newExec(exec, this, registerFile, scopeChain, -1);
 
     m_reentryDepth++;
@@ -805,9 +801,8 @@ JSValue* Machine::execute(EvalNode* evalNode, ExecState* exec, JSObject* thisObj
 
     registerFile->shrink(oldSize);
 
-#if JAVASCRIPT_PROFILING
-    Profiler::profiler()->didExecute(exec, evalNode->sourceURL(), evalNode->lineNo());
-#endif
+    if (*profiler)
+        (*profiler)->didExecute(exec, evalNode->sourceURL(), evalNode->lineNo());
 
     return result;
 }
@@ -879,11 +874,20 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
 
     JSValue* exceptionValue = 0;
     Instruction* handlerVPC = 0;
-    
+
     Register** registerBase = registerFile->basePointer();
     Instruction* vPC = codeBlock->instructions.begin();
     JSValue** k = codeBlock->jsValues.data();
+    Profiler** enabledProfilerReference = Profiler::enabledProfilerReference();
     
+#if HAVE(COMPUTED_GOTO)
+    // Yet another hack around GCC's various foibles, in this case fetching the
+    // profiler reference results in a regression.  Removing this indirection
+    // results in a 0.8% regression.
+    goto *(&&profilerFetchHack);
+    profilerFetchHack:
+#endif
+
     registerFile->setSafeForReentry(false);
 #define VM_CHECK_EXCEPTION() \
      do { \
@@ -1855,11 +1859,9 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
             JSObject* thisObject = r[codeBlock->thisRegister].u.jsObject;
 
             registerFile->setSafeForReentry(true);
-#if JAVASCRIPT_PROFILING
-            JSValue* result = callEval(exec, static_cast<JSObject*>(funcVal), thisObject, scopeChain, registerFile, r, argv, argc, exceptionValue);
-#else
+
             JSValue* result = callEval(exec, thisObject, scopeChain, registerFile, r, argv, argc, exceptionValue);
-#endif
+
             registerFile->setSafeForReentry(false);
             r = (*registerBase) + registerOffset;
 
@@ -1899,9 +1901,8 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
         CallType callType = v->getCallData(callData);
         
         if (callType == CallTypeJS) {
-#if JAVASCRIPT_PROFILING
-            Profiler::profiler()->willExecute(exec, static_cast<JSObject*>(v));
-#endif
+            if (*enabledProfilerReference)
+                (*enabledProfilerReference)->willExecute(exec, static_cast<JSObject*>(v));
             int registerOffset = r - (*registerBase);
             Register* callFrame = r + argv - CallFrameHeaderSize;
             int callFrameOffset = registerOffset + argv - CallFrameHeaderSize;
@@ -1927,9 +1928,8 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
         }
 
         if (callType == CallTypeNative) {
-#if JAVASCRIPT_PROFILING
-            Profiler::profiler()->willExecute(exec, static_cast<JSObject*>(v));
-#endif
+            if (*enabledProfilerReference)
+                (*enabledProfilerReference)->willExecute(exec, static_cast<JSObject*>(v));
             int registerOffset = r - (*registerBase);
 
             r[argv].u.jsValue = base == missingThisObjectMarker() ? exec->globalThisValue() : (r[base].u.jsValue)->toObject(exec); // "this" value
@@ -1944,9 +1944,8 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
             r = (*registerBase) + registerOffset;
             r[dst].u.jsValue = returnValue;
 
-#if JAVASCRIPT_PROFILING
-            Profiler::profiler()->didExecute(exec, static_cast<JSObject*>(v));
-#endif
+            if (*enabledProfilerReference)
+                (*enabledProfilerReference)->didExecute(exec, static_cast<JSObject*>(v));
             VM_CHECK_EXCEPTION();
 
             ++vPC;
@@ -1992,10 +1991,10 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
         exec->m_callFrameOffset = callerRegisterOffset - codeBlock->numLocals - CallFrameHeaderSize;
         int r0 = callFrame[ReturnValueRegister].u.i;
         r[r0].u.jsValue = returnValue;
-        
-#if JAVASCRIPT_PROFILING
-        Profiler::profiler()->didExecute(exec, callFrame[Callee].u.jsObject);
-#endif
+
+        if (*enabledProfilerReference)
+            (*enabledProfilerReference)->didExecute(exec, callFrame[Callee].u.jsObject);
+
         NEXT_OPCODE;
     }
     BEGIN_OPCODE(op_construct) {
@@ -2013,9 +2012,9 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
         JSObject* constructor = static_cast<JSObject*>(funcVal);
 
         if (constructType == ConstructTypeJS) {
-#if JAVASCRIPT_PROFILING
-            Profiler::profiler()->willExecute(exec, constructor);
-#endif
+            if (*enabledProfilerReference)
+                (*enabledProfilerReference)->willExecute(exec, constructor);
+
             int registerOffset = r - (*registerBase);
             Register* callFrame = r + argv - CallFrameHeaderSize;
             int callFrameOffset = registerOffset + argv - CallFrameHeaderSize;
@@ -2049,9 +2048,9 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
         }
 
         if (constructType == ConstructTypeNative) {
-#if JAVASCRIPT_PROFILING
-            Profiler::profiler()->willExecute(exec, constructor);
-#endif
+            if (*enabledProfilerReference)
+                (*enabledProfilerReference)->willExecute(exec, constructor);
+
             int registerOffset = r - (*registerBase);
 
             List args(&r[argv + 1].u.jsValue, argc - 1);
@@ -2063,9 +2062,9 @@ JSValue* Machine::privateExecute(ExecutionFlag flag, ExecState* exec, RegisterFi
             VM_CHECK_EXCEPTION();
             r[dst].u.jsValue = returnValue;
 
-#if JAVASCRIPT_PROFILING
-            Profiler::profiler()->didExecute(exec, constructor);
-#endif
+            if (*enabledProfilerReference)
+                (*enabledProfilerReference)->didExecute(exec, constructor);
+
             ++vPC;
             NEXT_OPCODE;
         }