8148117: Move sun.misc.Cleaner to jdk.internal.ref

Reviewed-by: alanb, rriggs
This commit is contained in:
Chris Hegarty 2016-02-02 08:59:52 +00:00
parent e5bf0846fa
commit 5765b5b4f0
13 changed files with 93 additions and 101 deletions

View File

@ -30,7 +30,7 @@ import java.lang.reflect.Field;
import static java.lang.invoke.MethodHandleNatives.Constants.*;
import static java.lang.invoke.MethodHandleStatics.*;
import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
import sun.misc.Cleaner;
import jdk.internal.ref.Cleaner;
/**
* The JVM interface for the method handles package is all here.

View File

@ -26,10 +26,10 @@
package java.lang.ref;
import jdk.internal.vm.annotation.DontInline;
import sun.misc.Cleaner;
import jdk.internal.HotSpotIntrinsicCandidate;
import jdk.internal.misc.JavaLangRefAccess;
import jdk.internal.misc.SharedSecrets;
import jdk.internal.ref.Cleaner;
/**
* Abstract base class for reference objects. This class defines the

View File

@ -28,9 +28,9 @@
package java.nio;
import java.io.FileDescriptor;
import sun.misc.Cleaner;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
import jdk.internal.ref.Cleaner;
import sun.nio.ch.DirectBuffer;

View File

@ -23,7 +23,7 @@
* questions.
*/
package sun.misc;
package jdk.internal.ref;
import java.lang.ref.*;
import java.security.AccessController;
@ -58,6 +58,7 @@ import java.security.PrivilegedAction;
public class Cleaner
extends PhantomReference<Object>
implements Runnable
{
// Dummy reference queue, needed because the PhantomReference constructor
@ -153,4 +154,11 @@ public class Cleaner
}
}
@Override public void run() {
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPackageAccess("jdk.internal.ref");
this.clean();
}
}

View File

@ -25,7 +25,7 @@
package sun.nio.ch;
import sun.misc.Cleaner;
import jdk.internal.ref.Cleaner;
public interface DirectBuffer {

View File

@ -47,7 +47,7 @@ import java.util.List;
import jdk.internal.misc.JavaIOFileDescriptorAccess;
import jdk.internal.misc.JavaNioAccess;
import jdk.internal.misc.SharedSecrets;
import sun.misc.Cleaner;
import jdk.internal.ref.Cleaner;
import sun.security.action.GetPropertyAction;
public class FileChannelImpl

View File

@ -26,7 +26,7 @@
package sun.nio.ch;
import java.nio.ByteBuffer;
import sun.misc.*;
import jdk.internal.ref.Cleaner;
/**

View File

@ -33,7 +33,7 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import jdk.internal.misc.Unsafe;
import sun.misc.Cleaner;
import jdk.internal.ref.Cleaner;
import sun.security.action.GetPropertyAction;

View File

@ -26,7 +26,7 @@
package sun.nio.fs;
import jdk.internal.misc.Unsafe;
import sun.misc.Cleaner;
import jdk.internal.ref.Cleaner;
/**
* A light-weight buffer in native memory.

View File

@ -78,6 +78,7 @@ jdk_lang = \
sun/reflect \
jdk/lambda \
jdk/internal/misc \
jdk/internal/ref \
vm
# All of the java.util package

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 2003, 2013, 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.
*/
/*
* @test
* @bug 4954921 8009259
* @library /test/lib/share/classes
* @build jdk.test.lib.*
* @build jdk.test.lib.process.*
* @run main ExitOnThrow
* @summary Ensure that if a cleaner throws an exception then the VM exits
*/
import java.util.Arrays;
import jdk.internal.ref.Cleaner;
import jdk.test.lib.JDKToolLauncher;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
public class ExitOnThrow {
static final String cp = System.getProperty("test.classes", ".");
public static void main(String[] args) throws Exception {
if (args.length == 0) {
String[] cmd = JDKToolLauncher.createUsingTestJDK("java")
.addToolArg("-cp")
.addToolArg(cp)
.addToolArg("ExitOnThrow")
.addToolArg("-executeCleaner")
.getCommand();
ProcessBuilder pb = new ProcessBuilder(cmd);
OutputAnalyzer out = ProcessTools.executeProcess(pb);
System.out.println("======================");
System.out.println(Arrays.toString(cmd));
String msg = " stdout: [" + out.getStdout() + "]\n" +
" stderr: [" + out.getStderr() + "]\n" +
" exitValue = " + out.getExitValue() + "\n";
System.out.println(msg);
if (out.getExitValue() != 1)
throw new RuntimeException("Unexpected exit code: " +
out.getExitValue());
} else {
Cleaner.create(new Object(),
() -> { throw new RuntimeException("Foo!"); } );
while (true) {
System.gc();
Thread.sleep(100);
}
}
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (c) 2003, 2013, 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.
*/
//
import sun.misc.*;
public class ExitOnThrow {
public static void main(String[] args) throws Exception {
Cleaner.create(new Object(),
new Runnable() {
public void run() {
throw new RuntimeException("Foo!");
}
});
while (true) {
System.gc();
Thread.sleep(100);
}
}
}

View File

@ -1,48 +0,0 @@
#! /bin/sh
#
# Copyright (c) 2003, 2012, 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.
#
#
# @test
# @bug 4954921 8009259
# @summary Ensure that if a cleaner throws an exception then the VM exits
#
# @build ExitOnThrow
# @run shell exitOnThrow.sh
# Command-line usage: sh exitOnThrow.sh /path/to/build
if [ -z "$TESTJAVA" ]; then
if [ $# -lt 1 ]; then exit 1; fi
TESTJAVA=$1; shift
TESTCLASSES=`pwd`
fi
if $TESTJAVA/bin/java ${TESTVMOPTS} -cp $TESTCLASSES ExitOnThrow; then
echo Failed: VM exited normally
exit 1
else
echo Passed: VM exited with code $?
exit 0
fi