8198441: Replace native Runtime::runFinalization0 method with shared secrets
authormchung
Tue, 20 Feb 2018 11:28:32 -0800
changeset 48922 906025796009
parent 48921 576e024f10b6
child 48923 b75c9e2e3b1f
8198441: Replace native Runtime::runFinalization0 method with shared secrets Reviewed-by: martin
make/mapfiles/libjava/mapfile-vers
src/java.base/share/classes/java/lang/Runtime.java
src/java.base/share/classes/java/lang/ref/Reference.java
src/java.base/share/classes/jdk/internal/misc/JavaLangRefAccess.java
src/java.base/share/native/libjava/Runtime.c
--- a/make/mapfiles/libjava/mapfile-vers	Tue Feb 20 17:49:15 2018 +0100
+++ b/make/mapfiles/libjava/mapfile-vers	Tue Feb 20 11:28:32 2018 -0800
@@ -203,7 +203,6 @@
 		Java_java_lang_Runtime_freeMemory;
 		Java_java_lang_Runtime_maxMemory;
 		Java_java_lang_Runtime_gc;
-		Java_java_lang_Runtime_runFinalization0;
 		Java_java_lang_Runtime_totalMemory;
 		Java_java_lang_Runtime_availableProcessors;
 		Java_java_lang_SecurityManager_getClassContext;
--- a/src/java.base/share/classes/java/lang/Runtime.java	Tue Feb 20 17:49:15 2018 +0100
+++ b/src/java.base/share/classes/java/lang/Runtime.java	Tue Feb 20 11:28:32 2018 -0800
@@ -35,6 +35,8 @@
 import java.util.List;
 import java.util.Optional;
 import java.util.StringTokenizer;
+
+import jdk.internal.misc.SharedSecrets;
 import jdk.internal.reflect.CallerSensitive;
 import jdk.internal.reflect.Reflection;
 
@@ -702,9 +704,6 @@
      */
     public native void gc();
 
-    /* Wormhole for calling java.lang.ref.Finalizer.runFinalization */
-    private static native void runFinalization0();
-
     /**
      * Runs the finalization methods of any objects pending finalization.
      * Calling this method suggests that the Java virtual machine expend
@@ -724,7 +723,7 @@
      * @see     java.lang.Object#finalize()
      */
     public void runFinalization() {
-        runFinalization0();
+        SharedSecrets.getJavaLangRefAccess().runFinalization();
     }
 
     /**
--- a/src/java.base/share/classes/java/lang/ref/Reference.java	Tue Feb 20 17:49:15 2018 +0100
+++ b/src/java.base/share/classes/java/lang/ref/Reference.java	Tue Feb 20 11:28:32 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, 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
@@ -235,6 +235,11 @@
             {
                 return Reference.waitForReferenceProcessing();
             }
+
+            @Override
+            public void runFinalization() {
+                Finalizer.runFinalization();
+            }
         });
     }
 
--- a/src/java.base/share/classes/jdk/internal/misc/JavaLangRefAccess.java	Tue Feb 20 17:49:15 2018 +0100
+++ b/src/java.base/share/classes/jdk/internal/misc/JavaLangRefAccess.java	Tue Feb 20 11:28:32 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, 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
@@ -36,4 +36,11 @@
      * {@link java.lang.ref.Reference}s, {@code false} otherwise.
      */
     boolean waitForReferenceProcessing() throws InterruptedException;
+
+    /**
+     * Runs the finalization methods of any objects pending finalization.
+     *
+     * Invoked by Runtime.runFinalization()
+     */
+    void runFinalization();
 }
--- a/src/java.base/share/native/libjava/Runtime.c	Tue Feb 20 17:49:15 2018 +0100
+++ b/src/java.base/share/native/libjava/Runtime.c	Tue Feb 20 11:28:32 2018 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2018, 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
@@ -65,19 +65,6 @@
     JVM_GC();
 }
 
-JNIEXPORT void JNICALL
-Java_java_lang_Runtime_runFinalization0(JNIEnv *env, jobject this)
-{
-    jclass cl;
-    jmethodID mid;
-
-    if ((cl = (*env)->FindClass(env, "java/lang/ref/Finalizer"))
-        && (mid = (*env)->GetStaticMethodID(env, cl,
-                                            "runFinalization", "()V"))) {
-        (*env)->CallStaticVoidMethod(env, cl, mid);
-    }
-}
-
 JNIEXPORT jint JNICALL
 Java_java_lang_Runtime_availableProcessors(JNIEnv *env, jobject this)
 {