summaryrefslogtreecommitdiff
path: root/vm/reference/java
diff options
context:
space:
mode:
Diffstat (limited to 'vm/reference/java')
-rw-r--r--vm/reference/java/lang/VMClass.java27
-rw-r--r--vm/reference/java/lang/VMClassLoader.java49
-rw-r--r--vm/reference/java/lang/VMProcess.java13
-rw-r--r--vm/reference/java/lang/VMSystem.java51
-rw-r--r--vm/reference/java/lang/VMThread.java7
-rw-r--r--vm/reference/java/security/VMSecureRandom.java134
6 files changed, 227 insertions, 54 deletions
diff --git a/vm/reference/java/lang/VMClass.java b/vm/reference/java/lang/VMClass.java
index 47a91da8c..25965068d 100644
--- a/vm/reference/java/lang/VMClass.java
+++ b/vm/reference/java/lang/VMClass.java
@@ -157,7 +157,7 @@ final class VMClass
* @param klass the Class object that's calling us
* @return the direct superclass of this class
*/
- static native <T> Class<? super T> getSuperclass(Class<T> klass);
+ static native Class getSuperclass(Class klass);
/**
* Get the interfaces this class <EM>directly</EM> implements, in the
@@ -284,31 +284,6 @@ final class VMClass
static native void throwException(Throwable t);
/**
- * Returns true if this class is a synthetic class, generated by the
- * compiler.
- *
- * @param klass the Class object that's calling us
- * @return whether this class is synthetic or not
- */
- static native boolean isSynthetic(Class klass);
-
- /**
- * Returns true if this class represents an annotation.
- *
- * @param klass the Class object that's calling us
- * @return whether this class is an annotation or not
- */
- static native boolean isAnnotation(Class klass);
-
- /**
- * Returns true if this class was declared as an enum.
- *
- * @param klass the Class object that's calling us
- * @return whether this class is an enumeration or not
- */
- static native boolean isEnum(Class klass);
-
- /**
* Returns the simple name for the specified class, as used in the source
* code. For normal classes, this is the content returned by
* <code>getName()</code> which follows the last ".". Anonymous
diff --git a/vm/reference/java/lang/VMClassLoader.java b/vm/reference/java/lang/VMClassLoader.java
index 48652c879..4caa58c2a 100644
--- a/vm/reference/java/lang/VMClassLoader.java
+++ b/vm/reference/java/lang/VMClassLoader.java
@@ -1,6 +1,6 @@
/* VMClassLoader.java -- Reference implementation of native interface
required by ClassLoader
- Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation
+ Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -39,20 +39,23 @@ exception statement from your version. */
package java.lang;
-import gnu.classpath.SystemProperties;
import gnu.classpath.Configuration;
-
+import gnu.classpath.SystemProperties;
import gnu.java.lang.InstrumentationImpl;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.lang.instrument.Instrumentation;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipFile;
@@ -239,12 +242,46 @@ final class VMClassLoader
/**
* Returns a String[] of native package names. The default
- * implementation returns an empty array, or you may decide
- * this needs native help.
+ * implementation tries to load a list of package from
+ * the META-INF/INDEX.LIST file in the boot jar file.
+ * If not found or if any exception is raised, it returns
+ * an empty array. You may decide this needs native help.
*/
private static String[] getBootPackages()
{
- return new String[0];
+ URL indexList = getResource("META-INF/INDEX.LIST");
+ if (indexList != null)
+ {
+ try
+ {
+ Set packageSet = new HashSet();
+ String line;
+ int lineToSkip = 3;
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(
+ indexList.openStream()));
+ while ((line = reader.readLine()) != null)
+ {
+ if (lineToSkip == 0)
+ {
+ if (line.length() == 0)
+ lineToSkip = 1;
+ else
+ packageSet.add(line.replace('/', '.'));
+ }
+ else
+ lineToSkip--;
+ }
+ reader.close();
+ return (String[]) packageSet.toArray(new String[packageSet.size()]);
+ }
+ catch (IOException e)
+ {
+ return new String[0];
+ }
+ }
+ else
+ return new String[0];
}
diff --git a/vm/reference/java/lang/VMProcess.java b/vm/reference/java/lang/VMProcess.java
index 1538178a3..076e5999d 100644
--- a/vm/reference/java/lang/VMProcess.java
+++ b/vm/reference/java/lang/VMProcess.java
@@ -42,6 +42,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -306,15 +307,19 @@ final class VMProcess extends Process
return new VMProcess(cmd, env, dir, false);
}
- static Process exec(List<String> cmd, Map<String, String> env,
+ static Process exec(List cmd, Map env,
File dir, boolean redirect) throws IOException
{
- String[] acmd = cmd.toArray(new String[cmd.size()]);
+ String[] acmd = (String[]) cmd.toArray(new String[cmd.size()]);
String[] aenv = new String[env.size()];
int i = 0;
- for (Map.Entry<String, String> entry : env.entrySet())
- aenv[i++] = entry.getKey() + "=" + entry.getValue();
+ Iterator iter = env.entrySet().iterator();
+ while (iter.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) iter.next();
+ aenv[i++] = entry.getKey() + "=" + entry.getValue();
+ }
return new VMProcess(acmd, aenv, dir, redirect);
}
diff --git a/vm/reference/java/lang/VMSystem.java b/vm/reference/java/lang/VMSystem.java
index 5ed2228c8..f96986df3 100644
--- a/vm/reference/java/lang/VMSystem.java
+++ b/vm/reference/java/lang/VMSystem.java
@@ -1,5 +1,5 @@
/* VMSystem.java -- helper for java.lang.system
- Copyright (C) 1998, 2002, 2004, 2005 Free Software Foundation
+ Copyright (C) 1998, 2002, 2004 Free Software Foundation
This file is part of GNU Classpath.
@@ -137,6 +137,31 @@ final class VMSystem
*/
public static native long currentTimeMillis();
+ /**
+ * <p>
+ * Returns the current value of a nanosecond-precise system timer.
+ * The value of the timer is an offset relative to some arbitrary fixed
+ * time, which may be in the future (making the value negative). This
+ * method is useful for timing events where nanosecond precision is
+ * required. This is achieved by calling this method before and after the
+ * event, and taking the difference betweent the two times:
+ * </p>
+ * <p>
+ * <code>long startTime = System.nanoTime();</code><br />
+ * <code>... <emph>event code</emph> ...</code><br />
+ * <code>long endTime = System.nanoTime();</code><br />
+ * <code>long duration = endTime - startTime;</code><br />
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63.
+ * </p>
+ *
+ * @return the time of a system timer in nanoseconds.
+ * @since 1.5
+ */
public static long nanoTime()
{
return currentTimeMillis() * 1000;
@@ -151,17 +176,6 @@ final class VMSystem
static native List environ();
/**
- * Gets the value of an environment variable from the current
- * environment.
- * Always returning null is a valid (but not very useful) implementation.
- *
- * @param name The name of the environment variable (will not be null).
- * @return The string value of the variable or null when the
- * environment variable is not defined.
- */
- static native String getenv(String k);
-
- /**
* Helper method which creates the standard input stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
@@ -182,7 +196,7 @@ final class VMSystem
{
return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
}
-
+
/**
* Helper method which creates the standard error stream.
* VM implementors may choose to construct these streams differently.
@@ -193,5 +207,14 @@ final class VMSystem
{
return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
}
-
+
+ /**
+ * Gets the value of an environment variable.
+ * Always returning null is a valid (but not very useful) implementation.
+ *
+ * @param name The name of the environment variable (will not be null).
+ * @return The string value of the variable or null when the
+ * environment variable is not defined.
+ */
+ static native String getenv(String name);
}
diff --git a/vm/reference/java/lang/VMThread.java b/vm/reference/java/lang/VMThread.java
index b864b7f81..302de6c35 100644
--- a/vm/reference/java/lang/VMThread.java
+++ b/vm/reference/java/lang/VMThread.java
@@ -1,5 +1,5 @@
/* VMThread -- VM interface for Thread of executable code
- Copyright (C) 2003, 2004, 2005 Free Software Foundation
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -123,9 +123,8 @@ final class VMThread
{
try
{
- Thread.UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
- if (handler == null)
- handler = thread.group;
+ Thread.UncaughtExceptionHandler handler;
+ handler = thread.getUncaughtExceptionHandler();
handler.uncaughtException(thread, t);
}
catch(Throwable ignore)
diff --git a/vm/reference/java/security/VMSecureRandom.java b/vm/reference/java/security/VMSecureRandom.java
new file mode 100644
index 000000000..dc67d8719
--- /dev/null
+++ b/vm/reference/java/security/VMSecureRandom.java
@@ -0,0 +1,134 @@
+/* VMSecureRandom.java -- random seed generator.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.security;
+
+import gnu.classpath.SystemProperties;
+import gnu.java.security.action.GetSecurityPropertyAction;
+
+import java.net.URL;
+
+/**
+ * VM-specific methods for generating real (or almost real) random
+ * seeds. VM implementors should write a version of this class that
+ * reads random bytes from some system source.
+ *
+ * <p>The default implementation of this class runs eight threads that
+ * increment counters in a tight loop, and XORs each counter to
+ * produce one byte of seed data. This is not very efficient, and is
+ * not guaranteed to be random (the thread scheduler is probably
+ * deterministic, after all). If possible, VM implementors should
+ * reimplement this class so it obtains a random seed from a system
+ * facility, such as a system entropy gathering device or hardware
+ * random number generator.
+ */
+final class VMSecureRandom
+{
+
+ /**
+ * Generate a random seed. Implementations are free to generate
+ * fewer random bytes than are requested, and leave the remaining
+ * bytes of the destination buffer as zeros. Implementations SHOULD,
+ * however, make a best-effort attempt to satisfy the request.
+ *
+ * @param buffer The destination buffer.
+ * @param offset The offset in the buffer to start putting bytes.
+ * @param length The number of random bytes to generate.
+ */
+ static int generateSeed(byte[] buffer, int offset, int length)
+ {
+ if (length < 0)
+ throw new IllegalArgumentException("length must be nonnegative");
+ if (offset < 0 || offset + length > buffer.length)
+ throw new IndexOutOfBoundsException();
+
+ Spinner[] spinners = new Spinner[8];
+ int n = 0x1;
+ for (int i = 0; i < spinners.length; i++)
+ {
+ spinners[i] = new Spinner((byte) n);
+ Thread t = new Thread(spinners[i]);
+ t.start();
+ n <<= 1;
+ }
+
+ // Wait until at least one spinner has started.
+ while (!(spinners[0].running || spinners[1].running || spinners[2].running
+ || spinners[3].running || spinners[4].running || spinners[5].running
+ || spinners[6].running || spinners[7].running))
+ {
+ Thread.yield();
+ }
+
+ for (int i = offset; i < length; i++)
+ {
+ buffer[i] = (byte) (spinners[0].value ^ spinners[1].value ^ spinners[2].value
+ ^ spinners[3].value ^ spinners[4].value ^ spinners[5].value
+ ^ spinners[6].value ^ spinners[7].value);
+ Thread.yield();
+ }
+
+ for (int i = 0; i < spinners.length; i++)
+ spinners[i].stop();
+
+ return length;
+ }
+
+ static class Spinner implements Runnable
+ {
+ volatile byte value;
+ volatile boolean running;
+
+ Spinner(final byte initial)
+ {
+ value = initial;
+ }
+
+ public void run()
+ {
+ running = true;
+ while (running)
+ value++;
+ }
+
+ private void stop()
+ {
+ running = false;
+ }
+ }
+} \ No newline at end of file