Refactor the PtrTag list as a macro so that we can auto-generate code that enumerates...
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2018 19:33:01 +0000 (19:33 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Mar 2018 19:33:01 +0000 (19:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183861
<rdar://problem/38716822>

Reviewed by Filip Pizlo.

Also added ptrTagName() to aid debugging.  ptrTagName() is implemented using this
new PtrTag macro list.

* CMakeLists.txt:
* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* runtime/PtrTag.cpp: Added.
(JSC::ptrTagName):
* runtime/PtrTag.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@229817 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/runtime/PtrTag.cpp [new file with mode: 0644]
Source/JavaScriptCore/runtime/PtrTag.h

index f3f9941..c607386 100644 (file)
@@ -83,6 +83,7 @@ set(JavaScriptCore_OBJECT_LUT_SOURCES
     runtime/NumberConstructor.cpp
     runtime/NumberPrototype.cpp
     runtime/ObjectConstructor.cpp
+    runtime/PtrTag.cpp
     runtime/ReflectObject.cpp
     runtime/RegExpConstructor.cpp
     runtime/RegExpPrototype.cpp
index a77cf70..44d3d9f 100644 (file)
@@ -1,5 +1,23 @@
 2018-03-21  Mark Lam  <mark.lam@apple.com>
 
+        Refactor the PtrTag list as a macro so that we can auto-generate code that enumerates each PtrTag.
+        https://bugs.webkit.org/show_bug.cgi?id=183861
+        <rdar://problem/38716822>
+
+        Reviewed by Filip Pizlo.
+
+        Also added ptrTagName() to aid debugging.  ptrTagName() is implemented using this
+        new PtrTag macro list.
+
+        * CMakeLists.txt:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * runtime/PtrTag.cpp: Added.
+        (JSC::ptrTagName):
+        * runtime/PtrTag.h:
+
+2018-03-21  Mark Lam  <mark.lam@apple.com>
+
         Use CodeBlock::instructions()[] and CodeBlock::bytecodeOffset() instead of doing own pointer math.
         https://bugs.webkit.org/show_bug.cgi?id=183857
         <rdar://problem/38712184>
index 962faec..221cc6f 100644 (file)
                FE6491381D78F3A300A694D4 /* ExceptionScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExceptionScope.cpp; sourceTree = "<group>"; };
                FE68C6351B90DDD90042BCB3 /* MacroAssemblerPrinter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MacroAssemblerPrinter.cpp; sourceTree = "<group>"; };
                FE68C6361B90DDD90042BCB3 /* MacroAssemblerPrinter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MacroAssemblerPrinter.h; sourceTree = "<group>"; };
+               FE6C1E57203FF6E200BDC2B7 /* PtrTag.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PtrTag.cpp; sourceTree = "<group>"; };
                FE6F56DC1E64E92000D17801 /* VMTraps.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VMTraps.cpp; sourceTree = "<group>"; };
                FE6F56DD1E64E92000D17801 /* VMTraps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMTraps.h; sourceTree = "<group>"; };
                FE80C1961D775B27008510C0 /* CatchScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CatchScope.h; sourceTree = "<group>"; };
                                79B00CBB1C6AB07E0088C65D /* ProxyObject.h */,
                                79160DBB1C8E3EC8008C085A /* ProxyRevoke.cpp */,
                                79160DBC1C8E3EC8008C085A /* ProxyRevoke.h */,
+                               FE6C1E57203FF6E200BDC2B7 /* PtrTag.cpp */,
                                FE9AE1C82032C887002B6934 /* PtrTag.h */,
                                0F5780A118FE1E98001E72D9 /* PureNaN.h */,
                                0F0CD4C015F1A6040032F1C0 /* PutDirectIndexMode.h */,
index d3735a1..b2d864f 100644 (file)
@@ -872,6 +872,7 @@ runtime/ObjectInitializationScope.cpp
 runtime/ObjectPrototype.cpp
 runtime/Operations.cpp
 runtime/Options.cpp
+runtime/PtrTag.cpp
 runtime/ProgramExecutable.cpp
 runtime/PromiseDeferredTimer.cpp
 runtime/PropertyDescriptor.cpp
diff --git a/Source/JavaScriptCore/runtime/PtrTag.cpp b/Source/JavaScriptCore/runtime/PtrTag.cpp
new file mode 100644 (file)
index 0000000..28e9ba3
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "PtrTag.h"
+
+#include <algorithm>
+
+namespace JSC {
+
+const char* ptrTagName(PtrTag tag)
+{
+#define HANDLE_PTRTAG_CASE(_tagName) case _tagName: return #_tagName;
+
+    switch (tag) {
+        FOR_EACH_PTRTAG_ENUM(HANDLE_PTRTAG_CASE)
+    default: return "<unknown>";
+    }
+
+#undef HANDLE_PTRTAG_CASE
+}
+
+} // namespace JSC
index 087d46e..703ff52 100644 (file)
 
 namespace JSC {
 
+#define FOR_EACH_PTRTAG_ENUM(v) \
+    v(NoPtrTag) \
+    v(NearCallPtrTag) \
+    v(NearJumpPtrTag) \
+    v(CFunctionPtrTag) \
+    \
+    v(BytecodePtrTag) \
+    v(BytecodeHelperPtrTag) \
+    v(CodeEntryPtrTag) \
+    v(CodeEntryWithArityCheckPtrTag) \
+    v(ExceptionHandlerPtrTag) \
+    v(JITCodePtrTag) \
+    v(JITOperationPtrTag) \
+    v(JITThunkPtrTag) \
+    v(NativeCodePtrTag) \
+    v(SlowPathPtrTag) \
+    \
+    v(Yarr8BitPtrTag) \
+    v(Yarr16BitPtrTag) \
+    v(YarrMatchOnly8BitPtrTag) \
+    v(YarrMatchOnly16BitPtrTag) \
+    v(YarrBacktrackPtrTag) \
+
+
 enum PtrTag : uintptr_t {
-    NoPtrTag = 0,
-    NearCallPtrTag,
-    NearJumpPtrTag,
-
-    CFunctionPtrTag,
-
-    BytecodePtrTag,
-    BytecodeHelperPtrTag,
-    CodeEntryPtrTag,
-    CodeEntryWithArityCheckPtrTag,
-    ExceptionHandlerPtrTag,
-    JITCodePtrTag,
-    JITOperationPtrTag,
-    JITThunkPtrTag,
-    NativeCodePtrTag,
-    SlowPathPtrTag,
-
-    Yarr8BitPtrTag,
-    Yarr16BitPtrTag,
-    YarrMatchOnly8BitPtrTag,
-    YarrMatchOnly16BitPtrTag,
-    YarrBacktrackPtrTag,
+#define DECLARE_PTRTAG_ENUM(tag)  tag,
+    FOR_EACH_PTRTAG_ENUM(DECLARE_PTRTAG_ENUM)
+#undef DECLARE_PTRTAG_ENUM
 };
 
+static_assert(static_cast<uintptr_t>(NoPtrTag) == static_cast<uintptr_t>(0), "");
+static_assert(static_cast<uintptr_t>(NearCallPtrTag) == static_cast<uintptr_t>(1), "");
+static_assert(static_cast<uintptr_t>(NearJumpPtrTag) == static_cast<uintptr_t>(2), "");
+
+JS_EXPORT_PRIVATE const char* ptrTagName(PtrTag);
+
 uintptr_t nextPtrTagID();
 
 #if !USE(POINTER_PROFILING)