changeset 13170:f294b4ee2d47

make CodeInstallResult enum independent of the actual values in C++ code
author twisti
date Mon, 25 Nov 2013 18:39:31 -0800
parents 680060a794a1
children c302ab46defe
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java src/share/vm/graal/graalEnv.hpp src/share/vm/graal/vmStructs_graal.hpp src/share/vm/runtime/vmStructs.cpp
diffstat 6 files changed, 62 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Tue Nov 26 00:53:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Mon Nov 25 18:39:31 2013 -0800
@@ -1143,6 +1143,11 @@
     @HotSpotVMConstant(name = "vmIntrinsics::_linkToSpecial") @Stable public int vmIntrinsicLinkToSpecial;
     @HotSpotVMConstant(name = "vmIntrinsics::_linkToInterface") @Stable public int vmIntrinsicLinkToInterface;
 
+    @HotSpotVMConstant(name = "GraalEnv::ok") @Stable public int codeInstallResultOk;
+    @HotSpotVMConstant(name = "GraalEnv::dependencies_failed") @Stable public int codeInstallResultDependenciesFailed;
+    @HotSpotVMConstant(name = "GraalEnv::cache_full") @Stable public int codeInstallResultCacheFull;
+    @HotSpotVMConstant(name = "GraalEnv::code_too_large") @Stable public int codeInstallResultCodeTooLarge;
+
     public boolean check() {
         for (Field f : getClass().getDeclaredFields()) {
             int modifiers = f.getModifiers();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Tue Nov 26 00:53:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Mon Nov 25 18:39:31 2013 -0800
@@ -27,6 +27,7 @@
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.*;
 import com.oracle.graal.hotspot.meta.*;
 
@@ -132,9 +133,49 @@
 
     Object lookupAppendixInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode);
 
-    // Must be kept in sync with enum in graalEnv.hpp
     public enum CodeInstallResult {
-        OK, DEPENDENCIES_FAILED, CACHE_FULL, CODE_TOO_LARGE
+        OK("ok"), DEPENDENCIES_FAILED("dependencies failed"), CACHE_FULL("code cache is full"), CODE_TOO_LARGE("code is too large");
+
+        private int value;
+        private String message;
+
+        private CodeInstallResult(String name) {
+            HotSpotVMConfig config = HotSpotGraalRuntime.runtime().getConfig();
+            switch (name) {
+                case "ok":
+                    this.value = config.codeInstallResultOk;
+                    break;
+                case "dependencies failed":
+                    this.value = config.codeInstallResultDependenciesFailed;
+                    break;
+                case "code cache is full":
+                    this.value = config.codeInstallResultCacheFull;
+                    break;
+                case "code is too large":
+                    this.value = config.codeInstallResultCodeTooLarge;
+                    break;
+                default:
+                    throw GraalInternalError.shouldNotReachHere("unknown enum name " + name);
+            }
+            this.message = name;
+        }
+
+        /**
+         * Returns the enum object for the given value.
+         */
+        public static CodeInstallResult getEnum(int value) {
+            for (CodeInstallResult e : values()) {
+                if (e.value == value) {
+                    return e;
+                }
+            }
+            throw GraalInternalError.shouldNotReachHere("unknown enum value " + value);
+        }
+
+        @Override
+        public String toString() {
+            return message;
+        }
     }
 
     /**
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Tue Nov 26 00:53:26 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Mon Nov 25 18:39:31 2013 -0800
@@ -39,7 +39,7 @@
 
     @Override
     public CodeInstallResult installCode(HotSpotCompiledCode compiledCode, HotSpotInstalledCode code, SpeculationLog speculationLog) {
-        return CodeInstallResult.values()[installCode0(compiledCode, code, (speculationLog == null) ? null : speculationLog.getRawMap())];
+        return CodeInstallResult.getEnum(installCode0(compiledCode, code, (speculationLog == null) ? null : speculationLog.getRawMap()));
     }
 
     @Override
--- a/src/share/vm/graal/graalEnv.hpp	Tue Nov 26 00:53:26 2013 +0100
+++ b/src/share/vm/graal/graalEnv.hpp	Mon Nov 25 18:39:31 2013 -0800
@@ -58,7 +58,6 @@
 
 public:
 
-  // Must be kept in sync with the enum in the HotSpot implementation of CompilerToVM
   enum CodeInstallResult {
      ok,
      dependencies_failed,
--- a/src/share/vm/graal/vmStructs_graal.hpp	Tue Nov 26 00:53:26 2013 +0100
+++ b/src/share/vm/graal/vmStructs_graal.hpp	Mon Nov 25 18:39:31 2013 -0800
@@ -26,14 +26,18 @@
 #define SHARE_VM_GRAAL_VMSTRUCTS_GRAAL_HPP
 
 #include "compiler/abstractCompiler.hpp"
+#include "graal/graalEnv.hpp"
 
 #define VM_STRUCTS_GRAAL(nonstatic_field, static_field)                       \
-                                                                              \
   static_field(java_lang_Class, _graal_mirror_offset, int)                    \
-                                                                              \
 
 #define VM_TYPES_GRAAL(declare_type, declare_toplevel_type)                   \
-                                                                              \
 
+#define VM_INT_CONSTANTS_GRAAL(declare_constant)                              \
+  declare_constant(Deoptimization::Reason_aliasing)                           \
+  declare_constant(GraalEnv::ok)                                              \
+  declare_constant(GraalEnv::dependencies_failed)                             \
+  declare_constant(GraalEnv::cache_full)                                      \
+  declare_constant(GraalEnv::code_too_large)                                  \
 
 #endif // SHARE_VM_GRAAL_VMSTRUCTS_GRAAL_HPP
--- a/src/share/vm/runtime/vmStructs.cpp	Tue Nov 26 00:53:26 2013 +0100
+++ b/src/share/vm/runtime/vmStructs.cpp	Mon Nov 25 18:39:31 2013 -0800
@@ -2196,8 +2196,7 @@
                          declare_preprocessor_constant,                   \
                          declare_c1_constant,                             \
                          declare_c2_constant,                             \
-                         declare_c2_preprocessor_constant,                \
-                         declare_graal_constant)                          \
+                         declare_c2_preprocessor_constant)                \
                                                                           \
   /******************/                                                    \
   /* Useful globals */                                                    \
@@ -2506,7 +2505,6 @@
   declare_constant(Deoptimization::Reason_age)                            \
   declare_constant(Deoptimization::Reason_predicate)                      \
   declare_constant(Deoptimization::Reason_loop_limit_check)               \
-  declare_graal_constant(Deoptimization::Reason_aliasing)                 \
   declare_constant(Deoptimization::Reason_LIMIT)                          \
   declare_constant(Deoptimization::Reason_RECORDED_LIMIT)                 \
                                                                           \
@@ -2869,13 +2867,6 @@
 # define GENERATE_C2_PREPROCESSOR_VM_INT_CONSTANT_ENTRY(name, value)
 #endif /* COMPILER1 */
 
-// Generate an int constant for a Graal build
-#ifdef GRAAL
-# define GENERATE_GRAAL_VM_INT_CONSTANT_ENTRY(name)  GENERATE_VM_INT_CONSTANT_ENTRY(name)
-#else
-# define GENERATE_GRAAL_VM_INT_CONSTANT_ENTRY(name)
-#endif
-
 //--------------------------------------------------------------------------------
 // VMLongConstantEntry macros
 //
@@ -3018,8 +3009,11 @@
                    GENERATE_PREPROCESSOR_VM_INT_CONSTANT_ENTRY,
                    GENERATE_C1_VM_INT_CONSTANT_ENTRY,
                    GENERATE_C2_VM_INT_CONSTANT_ENTRY,
-                   GENERATE_C2_PREPROCESSOR_VM_INT_CONSTANT_ENTRY,
-                   GENERATE_GRAAL_VM_INT_CONSTANT_ENTRY)
+                   GENERATE_C2_PREPROCESSOR_VM_INT_CONSTANT_ENTRY)
+
+#ifdef GRAAL
+  VM_INT_CONSTANTS_GRAAL(GENERATE_VM_INT_CONSTANT_ENTRY)
+#endif
 
 #if INCLUDE_ALL_GCS
   VM_INT_CONSTANTS_CMS(GENERATE_VM_INT_CONSTANT_ENTRY)