Imported Upstream version 4.2.1.36

Former-commit-id: fb75898888a02f4d3a74cf0a5b841681bc4c7fa8
This commit is contained in:
Xamarin Public Jenkins
2015-09-24 06:06:07 -04:00
committed by Jo Shields
parent 9668de7cb8
commit dd547c45d4
172 changed files with 6570 additions and 11015 deletions

View File

@@ -0,0 +1,30 @@
/*
Copyright (C) 2015 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.awt;
final class DebugSettings
{
static void init() { }
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (C) 2009 Volker Berlin (i-net software)
* Copyright (C) 2010 Karsten Heinrich (i-net software)
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -596,8 +596,23 @@ final class Win32ShellFolder2 extends ShellFolder {
}
// Needs to be accessible to Win32ShellFolderManager2
@cli.System.Security.SecurityCriticalAttribute.Annotation
static native String getFileSystemPath(int csidl) throws IOException, InterruptedException;
static String getFileSystemPath(final int csidl) throws IOException, InterruptedException {
String path = invoke(new Callable<String>() {
public String call() throws IOException {
return getFileSystemPath0(csidl);
}
}, IOException.class);
if (path != null) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
}
return path;
}
// NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details
private static native String getFileSystemPath0(int csidl) throws IOException;
// Return whether the path is a network root.
// Path is assumed to be non-null

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@@ -36,14 +36,15 @@ import java.security.PrivilegedAction;
import java.util.*;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Stream;
import cli.System.IntPtr;
import cli.System.Drawing.Bitmap;
import cli.System.Drawing.SystemIcons;
import sun.security.action.LoadLibraryAction;
import static sun.awt.shell.Win32ShellFolder2.*;
import sun.awt.OSInfo;
import sun.misc.ThreadGroupUtils;
// NOTE: This class supersedes Win32ShellFolderManager, which was removed
// from distribution after version 1.4.2.
@@ -139,6 +140,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (desktop == null) {
try {
desktop = new Win32ShellFolder2(DESKTOP);
} catch (SecurityException e) {
// Ignore error
} catch (IOException e) {
// Ignore error
} catch (InterruptedException e) {
@@ -152,6 +155,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (drives == null) {
try {
drives = new Win32ShellFolder2(DRIVES);
} catch (SecurityException e) {
// Ignore error
} catch (IOException e) {
// Ignore error
} catch (InterruptedException e) {
@@ -169,6 +174,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (path != null) {
recent = createShellFolder(getDesktop(), new File(path));
}
} catch (SecurityException e) {
// Ignore error
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) {
@@ -182,6 +189,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (network == null) {
try {
network = new Win32ShellFolder2(NETWORK);
} catch (SecurityException e) {
// Ignore error
} catch (IOException e) {
// Ignore error
} catch (InterruptedException e) {
@@ -206,6 +215,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
personal.setIsPersonal();
}
}
} catch (SecurityException e) {
// Ignore error
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) {
@@ -246,7 +257,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (file == null) {
file = getDesktop();
}
return file;
return checkFile(file);
} else if (key.equals("roots")) {
// Should be "History" and "Desktop" ?
if (roots == null) {
@@ -257,11 +268,11 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
roots = (File[])super.get(key);
}
}
return roots;
return checkFiles(roots);
} else if (key.equals("fileChooserComboBoxFolders")) {
Win32ShellFolder2 desktop = getDesktop();
if (desktop != null) {
if (desktop != null && checkFile(desktop) != null) {
ArrayList<File> folders = new ArrayList<File>();
Win32ShellFolder2 drives = getDrives();
@@ -272,15 +283,15 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
folders.add(desktop);
// Add all second level folders
File[] secondLevelFolders = desktop.listFiles();
File[] secondLevelFolders = checkFiles(desktop.listFiles());
Arrays.sort(secondLevelFolders);
for (File secondLevelFolder : secondLevelFolders) {
Win32ShellFolder2 folder = (Win32ShellFolder2) secondLevelFolder;
if (!folder.isFileSystem() || (folder.isDirectory() && !folder.isLink()) ) {
if (!folder.isFileSystem() || (folder.isDirectory() && !folder.isLink())) {
folders.add(folder);
// Add third level for "My Computer"
if (folder.equals(drives)) {
File[] thirdLevelFolders = folder.listFiles();
File[] thirdLevelFolders = checkFiles(folder.listFiles());
if (thirdLevelFolders != null && thirdLevelFolders.length > 0) {
List<File> thirdLevelFoldersList = Arrays.asList(thirdLevelFolders);
@@ -290,7 +301,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
}
}
}
return folders.toArray(new File[folders.size()]);
return checkFiles(folders);
} else {
return super.get(key);
}
@@ -327,7 +338,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
}
}
}
return folders.toArray(new File[folders.size()]);
return checkFiles(folders);
} else if (key.startsWith("fileChooserIcon ")) {
String name = key.substring(key.indexOf(" ") + 1);
@@ -373,6 +384,41 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return null;
}
private File checkFile(File file) {
SecurityManager sm = System.getSecurityManager();
return (sm == null || file == null) ? file : checkFile(file, sm);
}
private File checkFile(File file, SecurityManager sm) {
try {
sm.checkRead(file.getPath());
return file;
} catch (SecurityException se) {
return null;
}
}
private File[] checkFiles(File[] files) {
SecurityManager sm = System.getSecurityManager();
if (sm == null || files == null || files.length == 0) {
return files;
}
return checkFiles(Arrays.stream(files), sm);
}
private File[] checkFiles(List<File> files) {
SecurityManager sm = System.getSecurityManager();
if (sm == null || files.isEmpty()) {
return files.toArray(new File[files.size()]);
}
return checkFiles(files.stream(), sm);
}
private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
return filesStream.filter((file) -> checkFile(file, sm) != null)
.toArray(File[]::new);
}
/**
* Does <code>dir</code> represent a "computer" such as a node on the network, or
* "My Computer" on the desktop.

View File

@@ -0,0 +1,27 @@
/*
Copyright (C) 2015 Jeroen Frijters
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jeroen Frijters
jeroen@frijters.net
*/
package sun.java2d.loops;
// only needed at compile time, to satisfy import statement
public class TransformHelper { }

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 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
@@ -48,6 +48,7 @@ public class VM {
return suspended;
}
@SuppressWarnings("deprecation")
public static boolean allowThreadSuspension(ThreadGroup g, boolean b) {
return g.allowThreadSuspension(b);
}
@@ -145,7 +146,9 @@ public class VM {
*/
// public native static void writeJavaProfilerReport();
private static volatile boolean booted = false;
private static final Object lock = new Object();
static {
// [IKVM] force System properties initialization ("booting")
@@ -163,13 +166,27 @@ public class VM {
// the booted flag to determine whether it is safe to query the system
// properties).
public static void booted() {
booted = true;
synchronized (lock) {
booted = true;
lock.notifyAll();
}
}
public static boolean isBooted() {
return booted;
}
// Waits until VM completes initialization
//
// This method is invoked by the Finalizer thread
public static void awaitBooted() throws InterruptedException {
synchronized (lock) {
while (!booted) {
lock.wait();
}
}
}
// Returns the maximum amount of allocatable direct buffer memory.
// The directMemory variable is initialized during system initialization
// in the saveAndRemoveProperties method.
@@ -216,6 +233,14 @@ public class VM {
return allowArraySyntax;
}
/**
* Returns true if the given class loader is in the system domain
* in which all permissions are granted.
*/
public static boolean isSystemDomainLoader(ClassLoader loader) {
return loader == null;
}
/**
* Returns the system property of the specified key saved at
* system initialization time. This method should only be used
@@ -282,6 +307,9 @@ public class VM {
// used by sun.launcher.LauncherHelper
props.remove("sun.java.launcher.diag");
// used by sun.misc.URLClassPath
props.remove("sun.cds.enableSharedLookupCache");
}
// Initialize any miscellenous operating system settings that need to be
@@ -361,6 +389,12 @@ public class VM {
private final static int JVMTI_THREAD_STATE_WAITING_INDEFINITELY = 0x0010;
private final static int JVMTI_THREAD_STATE_WAITING_WITH_TIMEOUT = 0x0020;
/*
* Returns the first non-null class loader up the execution stack,
* or null if only code from the null class loader is on the stack.
*/
public static native ClassLoader latestUserDefinedLoader();
static {
initialize();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 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
@@ -33,13 +33,16 @@ public class Version {
"openjdk";
private static final String java_version =
"1.7.0-internal";
"1.8.0-internal";
private static final String java_runtime_name =
"OpenJDK Runtime Environment";
"OpenJDK Runtime Environment";
private static final String java_profile_name =
"";
private static final String java_runtime_version =
"1.7.0-internal-jeroen_2012_05_22_06_05-b00";
"1.8.0-internal-jeroen_2015_06_02_10_38-b00";
static {
init();
@@ -87,23 +90,28 @@ public class Version {
boolean isHeadless = false;
/* Report that we're running headless if the property is true */
String headless = System.getProperty("java.awt.headless");
if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
String headless = System.getProperty("java.awt.headless");
if ( (headless != null) && (headless.equalsIgnoreCase("true")) ) {
isHeadless = true;
}
}
/* First line: platform version. */
ps.println(launcher_name + " version \"" + java_version + "\"");
/* Second line: runtime version (ie, libraries). */
ps.print(java_runtime_name + " (build " + java_runtime_version);
ps.print(java_runtime_name + " (build " + java_runtime_version);
if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
// embedded builds report headless state
ps.print(", headless");
}
ps.println(')');
if (java_profile_name.length() > 0) {
// profile name
ps.print(", profile " + java_profile_name);
}
if (java_runtime_name.indexOf("Embedded") != -1 && isHeadless) {
// embedded builds report headless state
ps.print(", headless");
}
ps.println(')');
/* Third line: JVM information. */
String java_vm_name = System.getProperty("java.vm.name");
@@ -328,7 +336,6 @@ public class Version {
// Return false if not available which implies an old VM (Tiger or before).
private static native boolean getJvmVersionInfo();
private static native void getJdkVersionInfo();
}
// Help Emacs a little because this file doesn't end in .java.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
@@ -33,7 +33,7 @@ import java.nio.channels.*;
import java.nio.channels.spi.*;
import java.util.*;
import sun.net.ResourceManager;
import sun.net.ExtendedOptionsImpl;
/**
* An implementation of DatagramChannels.
@@ -169,6 +169,7 @@ class DatagramChannelImpl
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
// Perform security check before returning address
return Net.getRevealedLocalAddress(localAddress);
}
}
@@ -194,15 +195,8 @@ class DatagramChannelImpl
synchronized (stateLock) {
ensureOpen();
if (name == StandardSocketOptions.IP_TOS) {
// IPv4 only; no-op for IPv6
if (family == StandardProtocolFamily.INET) {
Net.setSocketOption(fd, family, name, value);
}
return this;
}
if (name == StandardSocketOptions.IP_MULTICAST_TTL ||
if (name == StandardSocketOptions.IP_TOS ||
name == StandardSocketOptions.IP_MULTICAST_TTL ||
name == StandardSocketOptions.IP_MULTICAST_LOOP)
{
// options are protocol dependent
@@ -255,16 +249,8 @@ class DatagramChannelImpl
synchronized (stateLock) {
ensureOpen();
if (name == StandardSocketOptions.IP_TOS) {
// IPv4 only; always return 0 on IPv6
if (family == StandardProtocolFamily.INET) {
return (T) Net.getSocketOption(fd, family, name);
} else {
return (T) Integer.valueOf(0);
}
}
if (name == StandardSocketOptions.IP_MULTICAST_TTL ||
if (name == StandardSocketOptions.IP_TOS ||
name == StandardSocketOptions.IP_MULTICAST_TTL ||
name == StandardSocketOptions.IP_MULTICAST_LOOP)
{
return (T) Net.getSocketOption(fd, family, name);
@@ -317,6 +303,9 @@ class DatagramChannelImpl
set.add(StandardSocketOptions.IP_MULTICAST_IF);
set.add(StandardSocketOptions.IP_MULTICAST_TTL);
set.add(StandardSocketOptions.IP_MULTICAST_LOOP);
if (ExtendedOptionsImpl.flowSupported()) {
set.add(jdk.net.ExtendedSocketOptions.SO_FLOW_SLA);
}
return Collections.unmodifiableSet(set);
}
}
@@ -553,7 +542,7 @@ class DatagramChannelImpl
return 0;
readerThread = NativeThread.current();
do {
n = IOUtil.read(fd, buf, -1, nd, readLock);
n = IOUtil.read(fd, buf, -1, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@@ -609,7 +598,7 @@ class DatagramChannelImpl
return 0;
writerThread = NativeThread.current();
do {
n = IOUtil.write(fd, buf, -1, nd, writeLock);
n = IOUtil.write(fd, buf, -1, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
@@ -747,6 +736,26 @@ class DatagramChannelImpl
// set or refresh local address
localAddress = Net.localAddress(fd);
// flush any packets already received.
boolean blocking = false;
synchronized (blockingLock()) {
try {
blocking = isBlocking();
// remainder of each packet thrown away
ByteBuffer tmpBuf = ByteBuffer.allocate(1);
if (blocking) {
configureBlocking(false);
}
do {
tmpBuf.clear();
} while (receive(tmpBuf) != null);
} finally {
if (blocking) {
configureBlocking(true);
}
}
}
}
}
}
@@ -1032,25 +1041,24 @@ class DatagramChannelImpl
int oldOps = sk.nioReadyOps();
int newOps = initialOps;
if ((ops & PollArrayWrapper.POLLNVAL) != 0) {
if ((ops & Net.POLLNVAL) != 0) {
// This should only happen if this channel is pre-closed while a
// selection operation is in progress
// ## Throw an error if this channel has not been pre-closed
return false;
}
if ((ops & (PollArrayWrapper.POLLERR
| PollArrayWrapper.POLLHUP)) != 0) {
if ((ops & (Net.POLLERR | Net.POLLHUP)) != 0) {
newOps = intOps;
sk.nioReadyOps(newOps);
return (newOps & ~oldOps) != 0;
}
if (((ops & PollArrayWrapper.POLLIN) != 0) &&
if (((ops & Net.POLLIN) != 0) &&
((intOps & SelectionKey.OP_READ) != 0))
newOps |= SelectionKey.OP_READ;
if (((ops & PollArrayWrapper.POLLOUT) != 0) &&
if (((ops & Net.POLLOUT) != 0) &&
((intOps & SelectionKey.OP_WRITE) != 0))
newOps |= SelectionKey.OP_WRITE;
@@ -1066,6 +1074,28 @@ class DatagramChannelImpl
return translateReadyOps(ops, 0, sk);
}
// package-private
int poll(int events, long timeout) throws IOException {
assert Thread.holdsLock(blockingLock()) && !isBlocking();
synchronized (readLock) {
int n = 0;
try {
begin();
synchronized (stateLock) {
if (!isOpen())
return 0;
readerThread = NativeThread.current();
}
n = Net.poll(fd, events, timeout);
} finally {
readerThread = 0;
end(n > 0);
}
return n;
}
}
/**
* Translates an interest operation set into a native poll event set
*/
@@ -1073,11 +1103,11 @@ class DatagramChannelImpl
int newOps = 0;
if ((ops & SelectionKey.OP_READ) != 0)
newOps |= PollArrayWrapper.POLLIN;
newOps |= Net.POLLIN;
if ((ops & SelectionKey.OP_WRITE) != 0)
newOps |= PollArrayWrapper.POLLOUT;
newOps |= Net.POLLOUT;
if ((ops & SelectionKey.OP_CONNECT) != 0)
newOps |= PollArrayWrapper.POLLIN;
newOps |= Net.POLLIN;
sk.selector.putEventOps(sk, newOps);
}
@@ -1106,7 +1136,7 @@ class DatagramChannelImpl
throws IOException;
static {
Util.load();
IOUtil.load();
initIDs();
}

View File

@@ -165,9 +165,9 @@ final class DotNetSelectorImpl extends SelectorImpl
private int updateSelectedKeys(ArrayList read, ArrayList write, ArrayList error)
{
updateCount++;
int keys = processFDSet(updateCount, read, PollArrayWrapper.POLLIN);
keys += processFDSet(updateCount, write, PollArrayWrapper.POLLCONN | PollArrayWrapper.POLLOUT);
keys += processFDSet(updateCount, error, PollArrayWrapper.POLLIN | PollArrayWrapper.POLLCONN | PollArrayWrapper.POLLOUT);
int keys = processFDSet(updateCount, read, Net.POLLIN);
keys += processFDSet(updateCount, write, Net.POLLCONN | Net.POLLOUT);
keys += processFDSet(updateCount, error, Net.POLLIN | Net.POLLCONN | Net.POLLOUT);
return keys;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@@ -33,12 +33,21 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.*;
import java.nio.channels.ClosedByInterruptException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.FileLockInterruptionException;
import java.nio.channels.NonReadableChannelException;
import java.nio.channels.NonWritableChannelException;
import java.nio.channels.OverlappingFileLockException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.List;
import java.security.AccessController;
import sun.misc.Cleaner;
import sun.misc.IoTrace;
import sun.security.action.GetPropertyAction;
public class FileChannelImpl
@@ -63,7 +72,8 @@ public class FileChannelImpl
// Required to prevent finalization of creating stream (immutable)
private final Object parent;
// The path of the referenced file (null if the parent stream is created with a file descriptor)
// The path of the referenced file
// (null if the parent stream is created with a file descriptor)
private final String path;
// Thread-safe set of IDs of native threads, for signalling
@@ -121,7 +131,7 @@ public class FileChannelImpl
}
}
nd.preClose(fd);
// signal any threads blocked on this channel
threads.signalAndWait();
if (parent != null) {
@@ -145,19 +155,17 @@ public class FileChannelImpl
synchronized (positionLock) {
int n = 0;
int ti = -1;
Object traceContext = IoTrace.fileReadBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return 0;
do {
n = IOUtil.read(fd, dst, -1, nd, positionLock);
n = IOUtil.read(fd, dst, -1, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
IoTrace.fileReadEnd(traceContext, n > 0 ? n : 0);
end(n > 0);
assert IOStatus.check(n);
}
@@ -175,7 +183,6 @@ public class FileChannelImpl
synchronized (positionLock) {
long n = 0;
int ti = -1;
Object traceContext = IoTrace.fileReadBegin(path);
try {
begin();
ti = threads.add();
@@ -187,7 +194,6 @@ public class FileChannelImpl
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
IoTrace.fileReadEnd(traceContext, n > 0 ? n : 0);
end(n > 0);
assert IOStatus.check(n);
}
@@ -201,20 +207,18 @@ public class FileChannelImpl
synchronized (positionLock) {
int n = 0;
int ti = -1;
Object traceContext = IoTrace.fileWriteBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return 0;
do {
n = IOUtil.write(fd, src, -1, nd, positionLock);
n = IOUtil.write(fd, src, -1, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
end(n > 0);
IoTrace.fileWriteEnd(traceContext, n > 0 ? n : 0);
assert IOStatus.check(n);
}
}
@@ -231,7 +235,6 @@ public class FileChannelImpl
synchronized (positionLock) {
long n = 0;
int ti = -1;
Object traceContext = IoTrace.fileWriteBegin(path);
try {
begin();
ti = threads.add();
@@ -243,7 +246,6 @@ public class FileChannelImpl
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
IoTrace.fileWriteEnd(traceContext, n > 0 ? n : 0);
end(n > 0);
assert IOStatus.check(n);
}
@@ -321,12 +323,10 @@ public class FileChannelImpl
}
}
public FileChannel truncate(long size) throws IOException {
public FileChannel truncate(long newSize) throws IOException {
ensureOpen();
if (size < 0)
throw new IllegalArgumentException();
if (size > size())
return this;
if (newSize < 0)
throw new IllegalArgumentException("Negative size");
if (!writable)
throw new NonWritableChannelException();
synchronized (positionLock) {
@@ -339,6 +339,14 @@ public class FileChannelImpl
if (!isOpen())
return null;
// get current size
long size;
do {
size = nd.size(fd);
} while ((size == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
// get current position
do {
p = position0(fd, -1);
@@ -347,20 +355,22 @@ public class FileChannelImpl
return null;
assert p >= 0;
// truncate file
do {
rv = nd.truncate(fd, size);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
// truncate file if given size is less than the current size
if (newSize < size) {
do {
rv = nd.truncate(fd, newSize);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
}
// [IKVM] in append mode we're not allowed to seek backwards, but the atomic append will honor the new file size
if (append)
return this;
// set position to size if greater than size
if (p > size)
p = size;
// if position is beyond new size then adjust it
if (p > newSize)
p = newSize;
do {
rv = (int)position0(fd, p);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
@@ -522,21 +532,30 @@ public class FileChannelImpl
if (!readable)
throw new NonReadableChannelException();
ensureOpen();
if (nd.needsPositionLock()) {
synchronized (positionLock) {
return readInternal(dst, position);
}
} else {
return readInternal(dst, position);
}
}
private int readInternal(ByteBuffer dst, long position) throws IOException {
assert !nd.needsPositionLock() || Thread.holdsLock(positionLock);
int n = 0;
int ti = -1;
Object traceContext = IoTrace.fileReadBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return -1;
do {
n = IOUtil.read(fd, dst, position, nd, positionLock);
n = IOUtil.read(fd, dst, position, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
IoTrace.fileReadEnd(traceContext, n > 0 ? n : 0);
end(n > 0);
assert IOStatus.check(n);
}
@@ -550,22 +569,31 @@ public class FileChannelImpl
if (!writable)
throw new NonWritableChannelException();
ensureOpen();
if (nd.needsPositionLock()) {
synchronized (positionLock) {
return writeInternal(src, position);
}
} else {
return writeInternal(src, position);
}
}
private int writeInternal(ByteBuffer src, long position) throws IOException {
assert !nd.needsPositionLock() || Thread.holdsLock(positionLock);
int n = 0;
int ti = -1;
Object traceContext = IoTrace.fileWriteBegin(path);
try {
begin();
ti = threads.add();
if (!isOpen())
return -1;
do {
n = IOUtil.write(fd, src, position, nd, positionLock);
n = IOUtil.write(fd, src, position, nd);
} while ((n == IOStatus.INTERRUPTED) && isOpen());
return IOStatus.normalize(n);
} finally {
threads.remove(ti);
end(n > 0);
IoTrace.fileWriteEnd(traceContext, n > 0 ? n : 0);
assert IOStatus.check(n);
}
}
@@ -642,6 +670,8 @@ public class FileChannelImpl
throws IOException
{
ensureOpen();
if (mode == null)
throw new NullPointerException("Mode is null");
if (position < 0L)
throw new IllegalArgumentException("Negative position");
if (size < 0L)
@@ -650,6 +680,7 @@ public class FileChannelImpl
throw new IllegalArgumentException("Position + size overflow");
if (size > Integer.MAX_VALUE)
throw new IllegalArgumentException("Size exceeds Integer.MAX_VALUE");
int imode = -1;
if (mode == MapMode.READ_ONLY)
imode = MAP_RO;
@@ -670,7 +701,15 @@ public class FileChannelImpl
ti = threads.add();
if (!isOpen())
return null;
if (size() < position + size) { // Extend file size
long filesize;
do {
filesize = nd.size(fd);
} while ((filesize == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
if (filesize < position + size) { // Extend file size
if (!writable) {
throw new IOException("Channel not open for writing " +
"- cannot extend file to required size");
@@ -679,6 +718,8 @@ public class FileChannelImpl
do {
rv = nd.truncate(fd, position + size);
} while ((rv == IOStatus.INTERRUPTED) && isOpen());
if (!isOpen())
return null;
}
if (size == 0) {
addr = 0;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 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
@@ -27,14 +27,16 @@ package sun.nio.ch;
import java.io.*;
import java.net.*;
import jdk.net.*;
import java.nio.channels.*;
import java.util.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import sun.net.ExtendedOptionsImpl;
class Net { // package-private
public class Net {
private Net() { }
@@ -45,12 +47,6 @@ class Net { // package-private
}
};
// Value of jdk.net.revealLocalAddress
private static boolean revealLocalAddress;
// True if jdk.net.revealLocalAddress had been read
private static volatile boolean propRevealLocalAddress;
// set to true if exclusive binding is on for Windows
private static final boolean exclusiveBind;
@@ -59,8 +55,8 @@ class Net { // package-private
if (availLevel >= 0) {
String exclBindProp =
java.security.AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty(
"sun.net.useExclusiveBind");
@@ -117,7 +113,7 @@ class Net { // package-private
return canJoin6WithIPv4Group0();
}
static InetSocketAddress checkAddress(SocketAddress sa) {
public static InetSocketAddress checkAddress(SocketAddress sa) {
if (sa == null)
throw new NullPointerException();
if (!(sa instanceof InetSocketAddress))
@@ -197,43 +193,19 @@ class Net { // package-private
if (addr == null || sm == null)
return addr;
if (!getRevealLocalAddress()) {
try{
sm.checkConnect(addr.getAddress().getHostAddress(), -1);
// Security check passed
} catch (SecurityException e) {
// Return loopback address only if security check fails
try{
sm.checkConnect(addr.getAddress().getHostAddress(), -1);
//Security check passed
} catch (SecurityException e) {
//Return loopback address
addr = getLoopbackAddress(addr.getPort());
}
addr = getLoopbackAddress(addr.getPort());
}
return addr;
}
static String getRevealedLocalAddressAsString(InetSocketAddress addr) {
if (!getRevealLocalAddress() && System.getSecurityManager() != null)
addr = getLoopbackAddress(addr.getPort());
return addr.toString();
}
private static boolean getRevealLocalAddress() {
if (!propRevealLocalAddress) {
try {
revealLocalAddress = Boolean.parseBoolean(
AccessController.doPrivileged(
new PrivilegedExceptionAction<String>() {
public String run() {
return System.getProperty(
"jdk.net.revealLocalAddress");
}
}));
} catch (Exception e) {
// revealLocalAddress is false
}
propRevealLocalAddress = true;
}
return revealLocalAddress;
return System.getSecurityManager() == null ? addr.toString() :
getLoopbackAddress(addr.getPort()).toString();
}
private static InetSocketAddress getLoopbackAddress(int port) {
@@ -327,6 +299,16 @@ class Net { // package-private
// only simple values supported by this method
Class<?> type = name.type();
if (type == SocketFlow.class) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new NetworkPermission("setOption.SO_FLOW_SLA"));
}
ExtendedOptionsImpl.setFlowOption(fd, (SocketFlow)value);
return;
}
if (type != Integer.class && type != Boolean.class)
throw new AssertionError("Should not reach here");
@@ -370,7 +352,8 @@ class Net { // package-private
}
boolean mayNeedConversion = (family == UNSPEC);
setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg);
boolean isIPv6 = (family == StandardProtocolFamily.INET6);
setIntOption0(fd, mayNeedConversion, key.level(), key.name(), arg, isIPv6);
}
static Object getSocketOption(FileDescriptor fd, ProtocolFamily family,
@@ -379,6 +362,16 @@ class Net { // package-private
{
Class<?> type = name.type();
if (type == SocketFlow.class) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new NetworkPermission("getOption.SO_FLOW_SLA"));
}
SocketFlow flow = SocketFlow.create();
ExtendedOptionsImpl.getFlowOption(fd, flow);
return flow;
}
// only simple values supported by this method
if (type != Integer.class && type != Boolean.class)
throw new AssertionError("Should not reach here");
@@ -430,7 +423,7 @@ class Net { // package-private
// Due to oddities SO_REUSEADDR on windows reuse is ignored
private static native FileDescriptor socket0(boolean preferIPv6, boolean stream, boolean reuse);
static void bind(FileDescriptor fd, InetAddress addr, int port)
public static void bind(FileDescriptor fd, InetAddress addr, int port)
throws IOException
{
bind(UNSPEC, fd, addr, port);
@@ -484,7 +477,7 @@ class Net { // package-private
private static native InetAddress localInetAddress(FileDescriptor fd)
throws IOException;
static InetSocketAddress localAddress(FileDescriptor fd)
public static InetSocketAddress localAddress(FileDescriptor fd)
throws IOException
{
return new InetSocketAddress(localInetAddress(fd), localPort(fd));
@@ -507,7 +500,10 @@ class Net { // package-private
throws IOException;
private static native void setIntOption0(FileDescriptor fd, boolean mayNeedConversion,
int level, int opt, int arg)
int level, int opt, int arg, boolean isIPv6)
throws IOException;
static native int poll(FileDescriptor fd, int events, long timeout)
throws IOException;
// -- Multicast support --
@@ -606,4 +602,15 @@ class Net { // package-private
static native int getInterface6(FileDescriptor fd) throws IOException;
/**
* Event masks for the various poll system calls.
* They will be set platform dependant in the static initializer below.
*/
public static final short POLLIN = 0x0001;
public static final short POLLCONN = 0x0002;
public static final short POLLOUT = 0x0004;
public static final short POLLERR = 0x0008;
public static final short POLLHUP = 0x0010;
public static final short POLLNVAL = 0x0020;
public static final short POLLREMOVE = 0x0800;
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright (c) 2001, 2002, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 sun.nio.ch;
class PollArrayWrapper
{
static final short POLLIN = 0x0001;
static final short POLLCONN = 0x0002;
static final short POLLOUT = 0x0004;
static final short POLLERR = 0x0008;
static final short POLLHUP = 0x0010;
static final short POLLNVAL = 0x0020;
static final short POLLREMOVE = 0x0800;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -24,7 +24,7 @@
* questions.
*
*/
// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
package sun.nio.ch;
import java.net.SocketOption;
import java.net.StandardSocketOptions;
@@ -34,7 +34,6 @@ import java.util.Map;
import java.util.HashMap;
import cli.System.Net.Sockets.SocketOptionLevel;
import cli.System.Net.Sockets.SocketOptionName;
class SocketOptionRegistry {
private SocketOptionRegistry() { }
private static class RegistryKey {
@@ -72,6 +71,7 @@ class SocketOptionRegistry {
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.MulticastInterface));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.IpTimeToLive));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET), new OptionKey(SocketOptionLevel.IP, SocketOptionName.MulticastLoopback));
map.put(new RegistryKey(StandardSocketOptions.IP_TOS, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, ikvm.internal.Winsock.IPV6_TCLASS));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_IF, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.MulticastInterface));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_TTL, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.IpTimeToLive));
map.put(new RegistryKey(StandardSocketOptions.IP_MULTICAST_LOOP, StandardProtocolFamily.INET6), new OptionKey(SocketOptionLevel.IPv6, SocketOptionName.MulticastLoopback));

View File

@@ -36,6 +36,8 @@ import cli.System.IO.FileMode;
import cli.System.IO.FileShare;
import cli.System.IO.FileStream;
import cli.System.IO.FileOptions;
import cli.System.Runtime.InteropServices.DllImportAttribute;
import cli.System.Runtime.InteropServices.Marshal;
import cli.System.Security.AccessControl.FileSystemRights;
import com.sun.nio.file.ExtendedOpenOption;
import java.io.FileDescriptor;
@@ -338,7 +340,7 @@ final class NetFileSystemProvider extends AbstractFileSystemProvider
}
}
return FileChannelImpl.open(open(npath.path, mode, rights, share, options), read, write, append, null);
return FileChannelImpl.open(open(npath.path, mode, rights, share, options), npath.path, read, write, append, null);
}
private static FileDescriptor open(String path, int mode, int rights, int share, int options) throws IOException
@@ -628,6 +630,7 @@ final class NetFileSystemProvider extends AbstractFileSystemProvider
NetPath nsource = NetPath.from(source);
NetPath ntarget = NetPath.from(target);
boolean overwrite = false;
boolean atomicMove = false;
for (CopyOption opt : options)
{
if (opt == StandardCopyOption.REPLACE_EXISTING)
@@ -636,7 +639,14 @@ final class NetFileSystemProvider extends AbstractFileSystemProvider
}
else if (opt == StandardCopyOption.ATOMIC_MOVE)
{
throw new AtomicMoveNotSupportedException(nsource.path, ntarget.path, "Unsupported copy option");
if (WINDOWS)
{
atomicMove = true;
}
else
{
throw new AtomicMoveNotSupportedException(nsource.path, ntarget.path, "Unsupported copy option");
}
}
else
{
@@ -651,6 +661,36 @@ final class NetFileSystemProvider extends AbstractFileSystemProvider
sm.checkRead(nsource.path);
sm.checkWrite(ntarget.path);
}
if (atomicMove)
{
int MOVEFILE_REPLACE_EXISTING = 1;
if (MoveFileEx(nsource.path, ntarget.path, MOVEFILE_REPLACE_EXISTING) == 0)
{
final int ERROR_FILE_NOT_FOUND = 2;
final int ERROR_PATH_NOT_FOUND = 3;
final int ERROR_ACCESS_DENIED = 5;
final int ERROR_NOT_SAME_DEVICE = 17;
final int ERROR_FILE_EXISTS = 80;
final int ERROR_ALREADY_EXISTS = 183;
int lastError = Marshal.GetLastWin32Error();
switch (lastError)
{
case ERROR_FILE_NOT_FOUND:
case ERROR_PATH_NOT_FOUND:
throw new NoSuchFileException(nsource.path, ntarget.path, null);
case ERROR_ACCESS_DENIED:
throw new AccessDeniedException(nsource.path, ntarget.path, null);
case ERROR_NOT_SAME_DEVICE:
throw new AtomicMoveNotSupportedException(nsource.path, ntarget.path, "Unsupported copy option");
case ERROR_FILE_EXISTS:
case ERROR_ALREADY_EXISTS:
throw new FileAlreadyExistsException(nsource.path, ntarget.path, null);
default:
throw new FileSystemException(nsource.path, ntarget.path, "Error " + lastError);
}
}
return;
}
try
{
if (false) throw new cli.System.ArgumentException();
@@ -711,6 +751,9 @@ final class NetFileSystemProvider extends AbstractFileSystemProvider
}
}
@DllImportAttribute.Annotation(value="kernel32", SetLastError=true)
private static native int MoveFileEx(String lpExistingFileName, String lpNewFileName, int dwFlags);
public boolean isSameFile(Path path, Path path2) throws IOException
{
if (path.equals(path2))

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
@@ -34,7 +34,6 @@
package sun.reflect;
import java.lang.reflect.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -47,17 +46,18 @@ public class Reflection {
view, where they are sensitive or they may contain VM-internal objects.
These Maps are updated very rarely. Rather than synchronize on
each access, we use copy-on-write */
private static volatile Map<Class,String[]> fieldFilterMap;
private static volatile Map<Class,String[]> methodFilterMap;
private static volatile Map<Class<?>,String[]> fieldFilterMap;
private static volatile Map<Class<?>,String[]> methodFilterMap;
static {
Map<Class,String[]> map = new HashMap<Class,String[]>();
Map<Class<?>,String[]> map = new HashMap<Class<?>,String[]>();
map.put(Reflection.class,
new String[] {"fieldFilterMap", "methodFilterMap"});
map.put(System.class, new String[] {"security"});
map.put(Class.class, new String[] {"classLoader"});
fieldFilterMap = map;
methodFilterMap = new HashMap<Class,String[]>();
methodFilterMap = new HashMap<>();
// [IKVM] to avoid initialization order issues, we actually add
// Unsafe.getUnsafe() here, instead of in Unsafe's class initializer
methodFilterMap.put(sun.misc.Unsafe.class, new String[] {"getUnsafe"});
@@ -67,21 +67,15 @@ public class Reflection {
ignoring frames associated with java.lang.reflect.Method.invoke()
and its implementation. */
@CallerSensitive
public static Class getCallerClass() {
return getCallerClass(2);
}
public static native Class<?> getCallerClass();
/** Returns the class of the method <code>realFramesToSkip</code>
frames up the stack (zero-based), ignoring frames associated
with java.lang.reflect.Method.invoke() and its implementation.
The first frame is that associated with this method, so
<code>getCallerClass(0)</code> returns the Class object for
sun.reflect.Reflection. Frames associated with
java.lang.reflect.Method.invoke() and its implementation are
completely ignored and do not count toward the number of "real"
frames skipped. */
@CallerSensitive
public static native Class getCallerClass(int realFramesToSkip);
/**
* @deprecated This method will be removed in JDK 9.
* This method is a private JDK API and retained temporarily for
* existing code to run until a replacement API is defined.
*/
@Deprecated
public static native Class<?> getCallerClass(int depth);
/** Retrieves the access flags written to the class file. For
inner classes these flags may differ from those returned by
@@ -91,18 +85,18 @@ public class Reflection {
to compatibility reasons; see 4471811. Only the values of the
low 13 bits (i.e., a mask of 0x1FFF) are guaranteed to be
valid. */
private static native int getClassAccessFlags(Class c);
public static native int getClassAccessFlags(Class<?> c);
/** A quick "fast-path" check to try to avoid getCallerClass()
calls. */
public static boolean quickCheckMemberAccess(Class memberClass,
public static boolean quickCheckMemberAccess(Class<?> memberClass,
int modifiers)
{
return Modifier.isPublic(getClassAccessFlags(memberClass) & modifiers);
}
public static void ensureMemberAccess(Class currentClass,
Class memberClass,
public static void ensureMemberAccess(Class<?> currentClass,
Class<?> memberClass,
Object target,
int modifiers)
throws IllegalAccessException
@@ -124,13 +118,13 @@ public class Reflection {
/*IKVM*/
private static native boolean checkInternalAccess(Class currentClass, Class memberClass);
public static boolean verifyMemberAccess(Class currentClass,
public static boolean verifyMemberAccess(Class<?> currentClass,
// Declaring class of field
// or method
Class memberClass,
Class<?> memberClass,
// May be NULL in case of statics
Object target,
int modifiers)
Object target,
int modifiers)
{
// Verify that currentClass can access a field, method, or
// constructor of memberClass, where that member's access bits are
@@ -192,7 +186,7 @@ public class Reflection {
if (Modifier.isProtected(modifiers)) {
// Additional test for protected members: JLS 6.6.2
Class targetClass = (target == null ? memberClass : target.getClass());
Class<?> targetClass = (target == null ? memberClass : target.getClass());
if (targetClass != currentClass) {
if (!gotIsSameClassPackage) {
isSameClassPackage = isSameClassPackage(currentClass, memberClass);
@@ -209,7 +203,7 @@ public class Reflection {
return true;
}
private static boolean isSameClassPackage(Class c1, Class c2) {
private static boolean isSameClassPackage(Class<?> c1, Class<?> c2) {
return isSameClassPackage(c1.getClassLoader(), c1.getName(),
c2.getClassLoader(), c2.getName());
}
@@ -264,8 +258,8 @@ public class Reflection {
}
}
static boolean isSubclassOf(Class queryClass,
Class ofClass)
static boolean isSubclassOf(Class<?> queryClass,
Class<?> ofClass)
{
while (queryClass != null) {
if (queryClass == ofClass) {
@@ -277,31 +271,31 @@ public class Reflection {
}
// fieldNames must contain only interned Strings
public static synchronized void registerFieldsToFilter(Class containingClass,
public static synchronized void registerFieldsToFilter(Class<?> containingClass,
String ... fieldNames) {
fieldFilterMap =
registerFilter(fieldFilterMap, containingClass, fieldNames);
}
// methodNames must contain only interned Strings
public static synchronized void registerMethodsToFilter(Class containingClass,
public static synchronized void registerMethodsToFilter(Class<?> containingClass,
String ... methodNames) {
methodFilterMap =
registerFilter(methodFilterMap, containingClass, methodNames);
}
private static Map<Class,String[]> registerFilter(Map<Class,String[]> map,
Class containingClass, String ... names) {
private static Map<Class<?>,String[]> registerFilter(Map<Class<?>,String[]> map,
Class<?> containingClass, String ... names) {
if (map.get(containingClass) != null) {
throw new IllegalArgumentException
("Filter already registered: " + containingClass);
}
map = new HashMap<Class,String[]>(map);
map = new HashMap<Class<?>,String[]>(map);
map.put(containingClass, names);
return map;
}
public static Field[] filterFields(Class containingClass,
public static Field[] filterFields(Class<?> containingClass,
Field[] fields) {
if (fieldFilterMap == null) {
// Bootstrapping
@@ -310,7 +304,7 @@ public class Reflection {
return (Field[])filter(fields, fieldFilterMap.get(containingClass));
}
public static Method[] filterMethods(Class containingClass, Method[] methods) {
public static Method[] filterMethods(Class<?> containingClass, Method[] methods) {
if (methodFilterMap == null) {
// Bootstrapping
return methods;
@@ -352,4 +346,27 @@ public class Reflection {
}
return newMembers;
}
/**
* Tests if the given method is caller-sensitive and the declaring class
* is defined by either the bootstrap class loader or extension class loader.
*/
public static boolean isCallerSensitive(Method m) {
final ClassLoader loader = m.getDeclaringClass().getClassLoader();
if (sun.misc.VM.isSystemDomainLoader(loader) || isExtClassLoader(loader)) {
return m.isAnnotationPresent(CallerSensitive.class);
}
return false;
}
private static boolean isExtClassLoader(ClassLoader loader) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
while (cl != null) {
if (cl.getParent() == null && cl == loader) {
return true;
}
cl = cl.getParent();
}
return false;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 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
@@ -32,12 +32,14 @@
package sun.reflect;
import java.lang.reflect.Field;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;
import sun.reflect.misc.ReflectUtil;
/** <P> The master factory for all reflective objects, both those in
java.lang.reflect (Fields, Methods, Constructors) as well as their
@@ -53,9 +55,9 @@ import java.security.PrivilegedAction;
public class ReflectionFactory {
private static Permission reflectionFactoryAccessPerm
private static final Permission reflectionFactoryAccessPerm
= new RuntimePermission("reflectionFactoryAccess");
private static ReflectionFactory soleInstance = new ReflectionFactory();
private static final ReflectionFactory soleInstance = new ReflectionFactory();
// Provides access to package-private mechanisms in java.lang.reflect
private static volatile LangReflectAccess langReflectAccess;
@@ -129,7 +131,7 @@ public class ReflectionFactory {
private native ConstructorAccessor newConstructorAccessor0(Constructor c);
public ConstructorAccessor newConstructorAccessor(Constructor c) {
public ConstructorAccessor newConstructorAccessor(Constructor<?> c) {
Class<?> declaringClass = c.getDeclaringClass();
if (Modifier.isAbstract(declaringClass.getModifiers())) {
return new InstantiationExceptionConstructorAccessorImpl(null);
@@ -195,14 +197,14 @@ public class ReflectionFactory {
/** Creates a new java.lang.reflect.Constructor. Access checks as
per java.lang.reflect.AccessibleObject are not overridden. */
public Constructor newConstructor(Class<?> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations)
public Constructor<?> newConstructor(Class<?> declaringClass,
Class<?>[] parameterTypes,
Class<?>[] checkedExceptions,
int modifiers,
int slot,
String signature,
byte[] annotations,
byte[] parameterAnnotations)
{
return langReflectAccess().newConstructor(declaringClass,
parameterTypes,
@@ -226,13 +228,13 @@ public class ReflectionFactory {
/** Gets the ConstructorAccessor object for a
java.lang.reflect.Constructor */
public ConstructorAccessor getConstructorAccessor(Constructor c) {
public ConstructorAccessor getConstructorAccessor(Constructor<?> c) {
return langReflectAccess().getConstructorAccessor(c);
}
/** Sets the ConstructorAccessor object for a
java.lang.reflect.Constructor */
public void setConstructorAccessor(Constructor c,
public void setConstructorAccessor(Constructor<?> c,
ConstructorAccessor accessor)
{
langReflectAccess().setConstructorAccessor(c, accessor);
@@ -259,6 +261,12 @@ public class ReflectionFactory {
return langReflectAccess().copyConstructor(arg);
}
/** Gets the byte[] that encodes TypeAnnotations on an executable.
*/
public byte[] getExecutableTypeAnnotationBytes(Executable ex) {
return langReflectAccess().getExecutableTypeAnnotationBytes(ex);
}
//--------------------------------------------------------------------------
//
// Routines used by serialization
@@ -267,8 +275,8 @@ public class ReflectionFactory {
private static native ConstructorAccessor newConstructorAccessorForSerialization(Class classToInstantiate, Constructor constructorToCall);
public Constructor newConstructorForSerialization
(Class<?> classToInstantiate, Constructor constructorToCall)
public Constructor<?> newConstructorForSerialization
(Class<?> classToInstantiate, Constructor<?> constructorToCall)
{
// Fast path
if (constructorToCall.getDeclaringClass() == classToInstantiate) {
@@ -276,18 +284,18 @@ public class ReflectionFactory {
}
ConstructorAccessor acc = newConstructorAccessorForSerialization(classToInstantiate, constructorToCall);
Constructor c = newConstructor(constructorToCall.getDeclaringClass(),
constructorToCall.getParameterTypes(),
constructorToCall.getExceptionTypes(),
constructorToCall.getModifiers(),
langReflectAccess().
getConstructorSlot(constructorToCall),
langReflectAccess().
getConstructorSignature(constructorToCall),
langReflectAccess().
getConstructorAnnotations(constructorToCall),
langReflectAccess().
getConstructorParameterAnnotations(constructorToCall));
Constructor<?> c = newConstructor(constructorToCall.getDeclaringClass(),
constructorToCall.getParameterTypes(),
constructorToCall.getExceptionTypes(),
constructorToCall.getModifiers(),
langReflectAccess().
getConstructorSlot(constructorToCall),
langReflectAccess().
getConstructorSignature(constructorToCall),
langReflectAccess().
getConstructorAnnotations(constructorToCall),
langReflectAccess().
getConstructorParameterAnnotations(constructorToCall));
setConstructorAccessor(c, acc);
return c;
}