changeset 21563:4f63449b4422

revived post option parsing handler notification
author Doug Simon <doug.simon@oracle.com>
date Fri, 29 May 2015 00:06:22 +0200
parents 47bebae7454f
children 2270a708ef23
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfigOptionsParsed.java graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptionsLoader.java graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/OptionsParsed.java src/share/vm/jvmci/jvmciRuntime.cpp src/share/vm/jvmci/jvmciRuntime.hpp src/share/vm/prims/nativeLookup.cpp
diffstat 8 files changed, 51 insertions(+), 93 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfigOptionsParsed.java	Thu May 28 21:58:33 2015 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfigOptionsParsed.java	Fri May 29 00:06:22 2015 +0200
@@ -32,7 +32,8 @@
 @ServiceProvider(OptionsParsed.class)
 class GraalDebugConfigOptionsParsed implements OptionsParsed {
 
-    public void apply() {
+    @Override
+    public void run() {
         assert !Debug.Initialization.isDebugInitialized();
         if (GraalDebugConfig.areDebugScopePatternsEnabled()) {
             System.setProperty(Debug.Initialization.INITIALIZER_PROPERTY_NAME, "true");
--- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java	Thu May 28 21:58:33 2015 +0200
+++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime.java	Fri May 29 00:06:22 2015 +0200
@@ -44,10 +44,6 @@
 
     static {
         try (InitTimer t0 = timer("HotSpotJVMCIRuntime.<clinit>")) {
-            try (InitTimer t = timer("initialize HotSpotOptions")) {
-                HotSpotOptions.initialize();
-            }
-
             try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) {
                 instance = new HotSpotJVMCIRuntime();
             }
--- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java	Thu May 28 21:58:33 2015 +0200
+++ b/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptions.java	Fri May 29 00:06:22 2015 +0200
@@ -22,9 +22,8 @@
  */
 package com.oracle.jvmci.hotspot;
 
-import static com.oracle.jvmci.hotspot.HotSpotOptionsLoader.*;
+import java.util.*;
 
-import com.oracle.jvmci.debug.*;
 import com.oracle.jvmci.options.*;
 import com.oracle.jvmci.runtime.*;
 
@@ -38,26 +37,28 @@
 
     private static final String JVMCI_OPTION_PREFIX = "-G:";
 
-    static {
-        // Debug should not be initialized until all options that may affect
-        // its initialization have been processed.
-        assert !Debug.Initialization.isDebugInitialized() : "The class " + Debug.class.getName() + " must not be initialized before the JVMCI runtime has been initialized. " +
-                        "This can be fixed by placing a call to " + JVMCI.class.getName() + ".getRuntime() on the path that triggers initialization of " + Debug.class.getName();
+    /**
+     * Called from VM.
+     */
+    static void printFlags() {
+        SortedMap<String, OptionDescriptor> options = new TreeMap<>();
+        for (Options opts : Services.load(Options.class)) {
+            for (OptionDescriptor desc : opts) {
+                if (isHotSpotOption(desc)) {
+                    String name = desc.getName();
+                    OptionDescriptor existing = options.put(name, desc);
+                    assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation();
+                }
+            }
+        }
 
-        for (OptionsParsed handler : Services.load(OptionsParsed.class)) {
-            handler.apply();
-        }
+        OptionUtils.printFlags(options, JVMCI_OPTION_PREFIX);
     }
 
     /**
-     * Ensures {@link HotSpotOptions} is initialized.
+     * Determines if a given option is a HotSpot command line option.
      */
-    public static void initialize() {
+    private static boolean isHotSpotOption(OptionDescriptor desc) {
+        return desc.getDeclaringClass().getName().startsWith("com.oracle.graal");
     }
-
-    static void printFlags() {
-        OptionUtils.printFlags(options, JVMCI_OPTION_PREFIX);
-    }
-
-    public native Object getOptionValue(String optionName);
 }
--- a/graal/com.oracle.jvmci.hotspot/src/com/oracle/jvmci/hotspot/HotSpotOptionsLoader.java	Thu May 28 21:58:33 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.jvmci.hotspot;
-
-import java.util.*;
-
-import com.oracle.jvmci.options.*;
-import com.oracle.jvmci.runtime.*;
-
-/**
- * Helper class for separating loading of options from option initialization at runtime.
- */
-class HotSpotOptionsLoader {
-    static final SortedMap<String, OptionDescriptor> options = new TreeMap<>();
-
-    /**
-     * Initializes {@link #options} from {@link Options} services.
-     */
-    static {
-        for (Options opts : Services.load(Options.class)) {
-            for (OptionDescriptor desc : opts) {
-                if (isHotSpotOption(desc)) {
-                    String name = desc.getName();
-                    OptionDescriptor existing = options.put(name, desc);
-                    assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation();
-                }
-            }
-        }
-    }
-
-    /**
-     * Determines if a given option is a HotSpot command line option.
-     */
-    private static boolean isHotSpotOption(OptionDescriptor desc) {
-        return desc.getDeclaringClass().getName().startsWith("com.oracle.graal");
-    }
-}
--- a/graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/OptionsParsed.java	Thu May 28 21:58:33 2015 +0200
+++ b/graal/com.oracle.jvmci.runtime/src/com/oracle/jvmci/runtime/OptionsParsed.java	Fri May 29 00:06:22 2015 +0200
@@ -30,5 +30,5 @@
     /**
      * Notifies this service that all JVMCI options have been parsed and initialized.
      */
-    void apply();
+    void run();
 }
--- a/src/share/vm/jvmci/jvmciRuntime.cpp	Thu May 28 21:58:33 2015 +0200
+++ b/src/share/vm/jvmci/jvmciRuntime.cpp	Fri May 29 00:06:22 2015 +0200
@@ -626,18 +626,13 @@
   SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_JVMCI_WKID, scan, CHECK);
 JVM_END
 
-// boolean com.oracle.jvmci.hotspot.HotSpotOptions.isCITimingEnabled()
-JVM_ENTRY(jboolean, JVM_IsCITimingEnabled(JNIEnv *env, jclass c))
-  return CITime || CITimeEach;
-JVM_END
-
 // private static JVMCIRuntime JVMCI.initializeRuntime()
 JVM_ENTRY(jobject, JVM_GetJVMCIRuntime(JNIEnv *env, jclass c))
   JVMCIRuntime::initialize_HotSpotJVMCIRuntime();
   return JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject();
 JVM_END
 
-// private static String[] Services.getServiceImpls(Class service)
+// private static Service[] Services.getServiceImpls(String serviceClass)
 JVM_ENTRY(jobject, JVM_GetJVMCIServiceImpls(JNIEnv *env, jclass c, jclass serviceClass))
   HandleMark hm;
   ResourceMark rm;
@@ -1046,6 +1041,8 @@
     if (closure.is_aborted()) {
       vm_abort(false);
     }
+
+    notify_options_set(THREAD);
   }
   OptionValue* printFlags = options->get(PRINT_FLAGS_ARG);
   if (printFlags != NULL && printFlags->boolean_value) {
@@ -1053,6 +1050,22 @@
   }
 }
 
+void JVMCIRuntime::notify_options_set(TRAPS) {
+  HandleMark hm(THREAD);
+  TempNewSymbol optionsParsedName = SymbolTable::new_symbol("com/oracle/jvmci/runtime/OptionsParsed", CHECK_ABORT);
+  KlassHandle optionsParsedClass = load_required_class(optionsParsedName);
+  objArrayHandle impls = get_service_impls(optionsParsedClass, THREAD);
+  int implsLen = impls->length();
+  if (implsLen != 0) {
+    for (int i = 0; i < implsLen; i++) {
+      JavaValue result(T_VOID);
+      JavaCallArguments args;
+      args.push_oop(impls->obj_at(i));
+      JavaCalls::call_interface(&result, optionsParsedClass, vmSymbols::run_method_name(), vmSymbols::void_method_signature(), &args, CHECK_ABORT);
+    }
+  }
+}
+
 void JVMCIRuntime::print_flags_helper(TRAPS) {
   // TODO(gd) write this in C++?
   HandleMark hm(THREAD);
@@ -1223,7 +1236,7 @@
 };
 
 
-Handle JVMCIRuntime::get_service_impls(KlassHandle serviceKlass, TRAPS) {
+objArrayHandle JVMCIRuntime::get_service_impls(KlassHandle serviceKlass, TRAPS) {
   const char* home = Arguments::get_java_home();
   const char* serviceName = serviceKlass->external_name();
   size_t path_len = strlen(home) + strlen("/lib/jvmci/services/") + strlen(serviceName) + 1;
@@ -1234,11 +1247,11 @@
   parse_lines(path, &closure, true); // TODO(gd) cache parsing results?
 
   GrowableArray<char*>* implNames = closure.implNames();
-  objArrayOop servicesOop = oopFactory::new_objArray(serviceKlass(), implNames->length(), CHECK_NH);
+  objArrayOop servicesOop = oopFactory::new_objArray(serviceKlass(), implNames->length(), CHECK_(objArrayHandle()));
   objArrayHandle services(THREAD, servicesOop);
   for (int i = 0; i < implNames->length(); ++i) {
     char* implName = implNames->at(i);
-    Handle service = create_Service(implName, CHECK_NH);
+    Handle service = create_Service(implName, CHECK_(objArrayHandle()));
     services->obj_at_put(i, service());
   }
   return services;
--- a/src/share/vm/jvmci/jvmciRuntime.hpp	Thu May 28 21:58:33 2015 +0200
+++ b/src/share/vm/jvmci/jvmciRuntime.hpp	Fri May 29 00:06:22 2015 +0200
@@ -69,7 +69,13 @@
    */
   static void parse_jvmci_options_file(OptionsValueTable* options);
 
+  /**
+   * Called after all options have been set to notify OptionsParsed providers.
+   */
+  static void notify_options_set(TRAPS);
+
   static void print_flags_helper(TRAPS);
+
   /**
    * Instantiates a service object, calls its default constructor and returns it.
    *
@@ -135,7 +141,7 @@
    * com.oracle.jvmci.api.runtime.Service), gets an array of objects, one per
    * known implementation of the service.
    */
-  static Handle get_service_impls(KlassHandle serviceKlass, TRAPS);
+  static objArrayHandle get_service_impls(KlassHandle serviceKlass, TRAPS);
 
   static void parse_lines(char* path, ParseClosure* closure, bool warnStatFailure);
 
--- a/src/share/vm/prims/nativeLookup.cpp	Thu May 28 21:58:33 2015 +0200
+++ b/src/share/vm/prims/nativeLookup.cpp	Fri May 29 00:06:22 2015 +0200
@@ -134,7 +134,6 @@
   jobject  JNICALL JVM_GetJVMCIServiceImpls(JNIEnv *env, jclass c, jclass serviceClass);
   jobject  JNICALL JVM_CreateTruffleRuntime(JNIEnv *env, jclass c);
   jobject  JNICALL JVM_CreateNativeFunctionInterface(JNIEnv *env, jclass c);
-  jboolean JNICALL JVM_IsCITimingEnabled(JNIEnv *env);
 #ifdef COMPILERJVMCI
   void     JNICALL JVM_PrintAndResetJVMCICompRate(JNIEnv *env, jclass c);
 #endif
@@ -156,7 +155,6 @@
   { CC"Java_com_oracle_truffle_api_Truffle_createRuntime",                     NULL, FN_PTR(JVM_CreateTruffleRuntime)               },
   { CC"Java_com_oracle_nfi_NativeFunctionInterfaceRuntime_createInterface",    NULL, FN_PTR(JVM_CreateNativeFunctionInterface)      },
   { CC"Java_com_oracle_jvmci_hotspot_CompilerToVMImpl_init",                   NULL, FN_PTR(JVM_InitializeJVMCINatives)             },
-  { CC"Java_com_oracle_jvmci_hotspot_HotSpotOptions_isCITimingEnabled",        NULL, FN_PTR(JVM_IsCITimingEnabled)                  },
 #endif
 };