6912065: final fields in objects need to support inlining optimizations for JSR 292
authorjrose
Wed, 13 Jan 2010 23:05:52 -0800
changeset 4644 2b1a1bc98168
parent 4643 61c659c91c57
child 4645 0c5f5b94e93a
6912065: final fields in objects need to support inlining optimizations for JSR 292 Reviewed-by: twisti, kvn
hotspot/src/share/vm/ci/ciField.cpp
hotspot/src/share/vm/runtime/globals.hpp
--- a/hotspot/src/share/vm/ci/ciField.cpp	Tue Jan 12 14:37:35 2010 -0800
+++ b/hotspot/src/share/vm/ci/ciField.cpp	Wed Jan 13 23:05:52 2010 -0800
@@ -161,6 +161,18 @@
          "bootstrap classes must not create & cache unshared fields");
 }
 
+static bool trust_final_non_static_fields(ciInstanceKlass* holder) {
+  if (holder == NULL)
+    return false;
+  if (holder->name() == ciSymbol::java_lang_System())
+    // Never trust strangely unstable finals:  System.out, etc.
+    return false;
+  // Even if general trusting is disabled, trust system-built closures in these packages.
+  if (holder->is_in_package("java/dyn") || holder->is_in_package("sun/dyn"))
+    return true;
+  return TrustFinalNonStaticFields;
+}
+
 void ciField::initialize_from(fieldDescriptor* fd) {
   // Get the flags, offset, and canonical holder of the field.
   _flags = ciFlags(fd->access_flags());
@@ -172,7 +184,7 @@
     if (!this->is_static()) {
       // A field can be constant if it's a final static field or if it's
       // a final non-static field of a trusted class ({java,sun}.dyn).
-      if (_holder->is_in_package("java/dyn") || _holder->is_in_package("sun/dyn")) {
+      if (trust_final_non_static_fields(_holder)) {
         _is_constant = true;
         return;
       }
--- a/hotspot/src/share/vm/runtime/globals.hpp	Tue Jan 12 14:37:35 2010 -0800
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Wed Jan 13 23:05:52 2010 -0800
@@ -3370,6 +3370,9 @@
   diagnostic(bool, OptimizeMethodHandles, true,                             \
           "when constructing method handles, try to improve them")          \
                                                                             \
+  experimental(bool, TrustFinalNonStaticFields, false,                      \
+          "trust final non-static declarations for constant folding")       \
+                                                                            \
   experimental(bool, EnableInvokeDynamic, false,                            \
           "recognize the invokedynamic instruction")                        \
                                                                             \