summaryrefslogtreecommitdiff
path: root/external/ikvm/openjdk/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'external/ikvm/openjdk/java/io')
-rw-r--r--external/ikvm/openjdk/java/io/FileInputStream.java45
-rw-r--r--external/ikvm/openjdk/java/io/FileOutputStream.java45
-rw-r--r--external/ikvm/openjdk/java/io/ObjectStreamClass.java46
-rw-r--r--external/ikvm/openjdk/java/io/ObjectStreamField.java10
-rw-r--r--external/ikvm/openjdk/java/io/RandomAccessFile.java59
5 files changed, 171 insertions, 34 deletions
diff --git a/external/ikvm/openjdk/java/io/FileInputStream.java b/external/ikvm/openjdk/java/io/FileInputStream.java
index a0bc2247eb..3547947f07 100644
--- a/external/ikvm/openjdk/java/io/FileInputStream.java
+++ b/external/ikvm/openjdk/java/io/FileInputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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,6 +27,7 @@ package java.io;
import java.nio.channels.FileChannel;
import sun.nio.ch.FileChannelImpl;
+import sun.misc.IoTrace;
/**
@@ -51,6 +52,9 @@ class FileInputStream extends InputStream
/* File Descriptor - handle to the open file */
private final FileDescriptor fd;
+ /* The path of the referenced file (null if the stream is created with a file descriptor) */
+ private final String path;
+
private FileChannel channel = null;
private final Object closeLock = new Object();
@@ -133,8 +137,14 @@ class FileInputStream extends InputStream
if (name == null) {
throw new NullPointerException();
}
+ /*
+ if (file.isInvalid()) {
+ throw new FileNotFoundException("Invalid file path");
+ }
+ */
fd = new FileDescriptor();
fd.incrementAndGetUseCount();
+ this.path = name;
open(name);
}
@@ -171,6 +181,7 @@ class FileInputStream extends InputStream
security.checkRead(fdObj);
}
fd = fdObj;
+ path = null;
/*
* FileDescriptor is being shared by streams.
@@ -197,9 +208,15 @@ class FileInputStream extends InputStream
* file is reached.
* @exception IOException if an I/O error occurs.
*/
- public int read() throws IOException
- {
- return fd.read();
+ public int read() throws IOException {
+ Object traceContext = IoTrace.fileReadBegin(path);
+ int b = 0;
+ try {
+ b = fd.read();
+ } finally {
+ IoTrace.fileReadEnd(traceContext, b == -1 ? 0 : 1);
+ }
+ return b;
}
/**
@@ -226,7 +243,14 @@ class FileInputStream extends InputStream
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[]) throws IOException {
- return readBytes(b, 0, b.length);
+ Object traceContext = IoTrace.fileReadBegin(path);
+ int bytesRead = 0;
+ try {
+ bytesRead = readBytes(b, 0, b.length);
+ } finally {
+ IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
+ }
+ return bytesRead;
}
/**
@@ -248,7 +272,14 @@ class FileInputStream extends InputStream
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[], int off, int len) throws IOException {
- return readBytes(b, off, len);
+ Object traceContext = IoTrace.fileReadBegin(path);
+ int bytesRead = 0;
+ try {
+ bytesRead = readBytes(b, off, len);
+ } finally {
+ IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
+ }
+ return bytesRead;
}
/**
@@ -376,7 +407,7 @@ class FileInputStream extends InputStream
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, true, false, this);
+ channel = FileChannelImpl.open(fd, path, true, false, this);
/*
* Increment fd's use count. Invoking the channel's close()
diff --git a/external/ikvm/openjdk/java/io/FileOutputStream.java b/external/ikvm/openjdk/java/io/FileOutputStream.java
index e931fe6823..dae9d4bc5e 100644
--- a/external/ikvm/openjdk/java/io/FileOutputStream.java
+++ b/external/ikvm/openjdk/java/io/FileOutputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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,6 +27,7 @@ package java.io;
import java.nio.channels.FileChannel;
import sun.nio.ch.FileChannelImpl;
+import sun.misc.IoTrace;
/**
@@ -58,6 +59,11 @@ class FileOutputStream extends OutputStream
private final FileDescriptor fd;
/**
+ * The path of the referenced file (null if the stream is created with a file descriptor)
+ */
+ private final String path;
+
+ /**
* True if the file is opened for append.
*/
private final boolean append;
@@ -205,9 +211,14 @@ class FileOutputStream extends OutputStream
if (name == null) {
throw new NullPointerException();
}
+ /*
+ if (file.isInvalid()) {
+ throw new FileNotFoundException("Invalid file path");
+ }
+ */
this.fd = new FileDescriptor();
this.append = append;
-
+ this.path = name;
fd.incrementAndGetUseCount();
open(name, append);
}
@@ -244,6 +255,7 @@ class FileOutputStream extends OutputStream
security.checkWrite(fdObj);
}
this.fd = fdObj;
+ this.path = null;
this.append = false;
/*
@@ -287,7 +299,14 @@ class FileOutputStream extends OutputStream
* @exception IOException if an I/O error occurs.
*/
public void write(int b) throws IOException {
- write(b, append);
+ Object traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
+ write(b, append);
+ bytesWritten = 1;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
@@ -312,7 +331,14 @@ class FileOutputStream extends OutputStream
* @exception IOException if an I/O error occurs.
*/
public void write(byte b[]) throws IOException {
- writeBytes(b, 0, b.length, append);
+ Object traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
+ writeBytes(b, 0, b.length, append);
+ bytesWritten = b.length;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
@@ -325,7 +351,14 @@ class FileOutputStream extends OutputStream
* @exception IOException if an I/O error occurs.
*/
public void write(byte b[], int off, int len) throws IOException {
- writeBytes(b, off, len, append);
+ Object traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
+ writeBytes(b, off, len, append);
+ bytesWritten = len;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
@@ -408,7 +441,7 @@ class FileOutputStream extends OutputStream
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, false, true, append, this);
+ channel = FileChannelImpl.open(fd, path, false, true, append, this);
/*
* Increment fd's use count. Invoking the channel's close()
diff --git a/external/ikvm/openjdk/java/io/ObjectStreamClass.java b/external/ikvm/openjdk/java/io/ObjectStreamClass.java
index 7cca355287..97489b1eb8 100644
--- a/external/ikvm/openjdk/java/io/ObjectStreamClass.java
+++ b/external/ikvm/openjdk/java/io/ObjectStreamClass.java
@@ -50,7 +50,10 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import sun.misc.Unsafe;
+import sun.reflect.CallerSensitive;
+import sun.reflect.Reflection;
import sun.reflect.ReflectionFactory;
+import sun.reflect.misc.ReflectUtil;
/**
* Serialization's descriptor for classes. It contains the name and
@@ -262,7 +265,17 @@ public class ObjectStreamClass implements Serializable {
*
* @return the <code>Class</code> instance that this descriptor represents
*/
+ @CallerSensitive
public Class<?> forClass() {
+ if (cl == null) {
+ return null;
+ }
+ if (System.getSecurityManager() != null) {
+ Class<?> caller = Reflection.getCallerClass();
+ if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), cl.getClassLoader())) {
+ ReflectUtil.checkPackageAccess(cl);
+ }
+ }
return cl;
}
@@ -1156,7 +1169,14 @@ public class ObjectStreamClass implements Serializable {
end = end.getSuperclass();
}
+ HashSet<String> oscNames = new HashSet<>(3);
+
for (ObjectStreamClass d = this; d != null; d = d.superDesc) {
+ if (oscNames.contains(d.name)) {
+ throw new InvalidClassException("Circular reference.");
+ } else {
+ oscNames.add(d.name);
+ }
// search up inheritance hierarchy for class with matching name
String searchName = (d.cl != null) ? d.cl.getName() : d.name;
@@ -1848,8 +1868,10 @@ public class ObjectStreamClass implements Serializable {
private final ObjectStreamField[] fields;
/** number of primitive fields */
private final int numPrimFields;
- /** unsafe field keys */
- private final long[] keys;
+ /** unsafe field keys for reading fields - may contain dupes */
+ private final long[] readKeys;
+ /** unsafe fields keys for writing fields - no dupes */
+ private final long[] writeKeys;
/** field data offsets */
private final int[] offsets;
/** field type codes */
@@ -1867,16 +1889,22 @@ public class ObjectStreamClass implements Serializable {
FieldReflector(ObjectStreamField[] fields) {
this.fields = fields;
int nfields = fields.length;
- keys = new long[nfields];
+ readKeys = new long[nfields];
+ writeKeys = new long[nfields];
offsets = new int[nfields];
typeCodes = new char[nfields];
ArrayList<Class<?>> typeList = new ArrayList<>();
+ Set<Long> usedKeys = new HashSet<>();
+
for (int i = 0; i < nfields; i++) {
ObjectStreamField f = fields[i];
Field rf = f.getField();
- keys[i] = (rf != null) ?
+ long key = (rf != null) ?
unsafe.objectFieldOffset(rf) : Unsafe.INVALID_FIELD_OFFSET;
+ readKeys[i] = key;
+ writeKeys[i] = usedKeys.add(key) ?
+ key : Unsafe.INVALID_FIELD_OFFSET;
offsets[i] = f.getOffset();
typeCodes[i] = f.getTypeCode();
if (!f.isPrimitive()) {
@@ -1912,7 +1940,7 @@ public class ObjectStreamClass implements Serializable {
* in array should be equal to Unsafe.INVALID_FIELD_OFFSET.
*/
for (int i = 0; i < numPrimFields; i++) {
- long key = keys[i];
+ long key = readKeys[i];
int off = offsets[i];
switch (typeCodes[i]) {
case 'Z':
@@ -1963,7 +1991,7 @@ public class ObjectStreamClass implements Serializable {
throw new NullPointerException();
}
for (int i = 0; i < numPrimFields; i++) {
- long key = keys[i];
+ long key = writeKeys[i];
if (key == Unsafe.INVALID_FIELD_OFFSET) {
continue; // discard value
}
@@ -2024,7 +2052,7 @@ public class ObjectStreamClass implements Serializable {
switch (typeCodes[i]) {
case 'L':
case '[':
- vals[offsets[i]] = unsafe.getObject(obj, keys[i]);
+ vals[offsets[i]] = unsafe.getObject(obj, readKeys[i]);
break;
default:
@@ -2045,7 +2073,7 @@ public class ObjectStreamClass implements Serializable {
throw new NullPointerException();
}
for (int i = numPrimFields; i < fields.length; i++) {
- long key = keys[i];
+ long key = writeKeys[i];
if (key == Unsafe.INVALID_FIELD_OFFSET) {
continue; // discard value
}
@@ -2148,7 +2176,7 @@ public class ObjectStreamClass implements Serializable {
}
}
- private static native Object getFastFieldReflector(Object fields);
+ private static native Object getFastFieldReflector(ObjectStreamField[] fields);
/**
* FieldReflector cache lookup key. Keys are considered equal if they
diff --git a/external/ikvm/openjdk/java/io/ObjectStreamField.java b/external/ikvm/openjdk/java/io/ObjectStreamField.java
index c2d1ffe174..1d7c2cdf1e 100644
--- a/external/ikvm/openjdk/java/io/ObjectStreamField.java
+++ b/external/ikvm/openjdk/java/io/ObjectStreamField.java
@@ -26,6 +26,9 @@
package java.io;
import java.lang.reflect.Field;
+import sun.reflect.CallerSensitive;
+import sun.reflect.Reflection;
+import sun.reflect.misc.ReflectUtil;
/**
* A description of a Serializable field from a Serializable class. An array
@@ -163,7 +166,14 @@ public class ObjectStreamField
* @return a <code>Class</code> object representing the type of the
* serializable field
*/
+ @CallerSensitive
public Class<?> getType() {
+ if (System.getSecurityManager() != null) {
+ Class<?> caller = Reflection.getCallerClass();
+ if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), type.getClassLoader())) {
+ ReflectUtil.checkPackageAccess(type);
+ }
+ }
return type;
}
diff --git a/external/ikvm/openjdk/java/io/RandomAccessFile.java b/external/ikvm/openjdk/java/io/RandomAccessFile.java
index 3cddafd2f4..61fc27a7e4 100644
--- a/external/ikvm/openjdk/java/io/RandomAccessFile.java
+++ b/external/ikvm/openjdk/java/io/RandomAccessFile.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 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,6 +27,7 @@ package java.io;
import java.nio.channels.FileChannel;
import sun.nio.ch.FileChannelImpl;
+import sun.misc.IoTrace;
/**
@@ -62,6 +63,9 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
private FileChannel channel = null;
private boolean rw;
+ /* The path of the referenced file */
+ private final String path;
+
private Object closeLock = new Object();
private volatile boolean closed = false;
@@ -228,8 +232,14 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
if (name == null) {
throw new NullPointerException();
}
+ /*
+ if (file.isInvalid()) {
+ throw new FileNotFoundException("Invalid file path");
+ }
+ */
fd = new FileDescriptor();
fd.incrementAndGetUseCount();
+ this.path = name;
open(name, imode);
}
@@ -267,7 +277,7 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
public final FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
- channel = FileChannelImpl.open(fd, true, rw, this);
+ channel = FileChannelImpl.open(fd, path, true, rw, this);
/*
* FileDescriptor could be shared by FileInputStream or
@@ -325,9 +335,15 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @exception IOException if an I/O error occurs. Not thrown if
* end-of-file has been reached.
*/
- public int read() throws IOException
- {
- return fd.read();
+ public int read() throws IOException {
+ Object traceContext = IoTrace.fileReadBegin(path);
+ int b = 0;
+ try {
+ b = fd.read();
+ } finally {
+ IoTrace.fileReadEnd(traceContext, b == -1 ? 0 : 1);
+ }
+ return b;
}
/**
@@ -339,7 +355,14 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
*/
private int readBytes(byte b[], int off, int len) throws IOException
{
- return fd.readBytes(b, off, len);
+ Object traceContext = IoTrace.fileReadBegin(path);
+ int bytesRead = 0;
+ try {
+ bytesRead = fd.readBytes(b, off, len);
+ } finally {
+ IoTrace.fileReadEnd(traceContext, bytesRead == -1 ? 0 : bytesRead);
+ }
+ return bytesRead;
}
/**
@@ -479,9 +502,15 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @param b the <code>byte</code> to be written.
* @exception IOException if an I/O error occurs.
*/
- public void write(int b) throws IOException
- {
- fd.write(b);
+ public void write(int b) throws IOException {
+ Object traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
+ fd.write(b);
+ bytesWritten = 1;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**
@@ -492,9 +521,15 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
- private void writeBytes(byte b[], int off, int len) throws IOException
- {
- fd.writeBytes(b, off, len);
+ private void writeBytes(byte b[], int off, int len) throws IOException {
+ Object traceContext = IoTrace.fileWriteBegin(path);
+ int bytesWritten = 0;
+ try {
+ fd.writeBytes(b, off, len);
+ bytesWritten = len;
+ } finally {
+ IoTrace.fileWriteEnd(traceContext, bytesWritten);
+ }
}
/**