Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

preliminary support for using OpenJDK's class library

Whereas the GNU Classpath port used the strategy of patching Classpath
with core classes from Avian so as to minimize changes to the VM, this
port uses the opposite strategy: abstract and isolate
classpath-specific features in the VM similar to how we abstract away
platform-specific features in system.h.  This allows us to use an
unmodified copy of OpenJDK's class library, including its core classes
and augmented by a few VM-specific classes in the "avian" package.
  • Loading branch information...
commit cddea7187d1886a521abbec719691d4fda8135d8 1 parent 17c1a55
@dicej dicej authored
Showing with 4,452 additions and 1,603 deletions.
  1. +1 −1  classpath/avian/Addendum.java
  2. +268 −0 classpath/avian/Classes.java
  3. +13 −0 classpath/avian/FieldAddendum.java
  4. +15 −0 classpath/avian/MethodAddendum.java
  5. +2 −274 classpath/avian/SystemClassLoader.java
  6. +1 −1  classpath/avian/VMField.java
  7. +1 −1  classpath/avian/VMMethod.java
  8. +4 −0 classpath/avian/resource/Handler.java
  9. +0 −1  classpath/java-lang.cpp
  10. +31 −29 classpath/java/lang/Class.java
  11. +1 −1  classpath/java/lang/OutOfMemoryError.java
  12. +1 −1  classpath/java/lang/StackTraceElement.java
  13. +4 −6 classpath/java/lang/ref/ReferenceQueue.java
  14. +1 −1  classpath/java/lang/reflect/Field.java
  15. +91 −112 makefile
  16. +288 −0 openjdk.ld
  17. +13 −754 src/builtin.cpp
  18. +601 −0 src/classpath-avian.cpp
  19. +271 −0 src/classpath-common.h
  20. +2,096 −0 src/classpath-openjdk.cpp
  21. +10 −0 src/common.h
  22. +1 −1  src/compile-x86.S
  23. +73 −37 src/compile.cpp
  24. +4 −4 src/continuations-x86.S
  25. +123 −67 src/interpret.cpp
  26. +146 −13 src/jnienv.cpp
  27. +165 −96 src/machine.cpp
  28. +119 −170 src/machine.h
  29. +1 −1  src/posix.cpp
  30. +3 −4 src/process.cpp
  31. +1 −1  src/process.h
  32. +4 −0 src/processor.h
  33. +1 −1  src/system.h
  34. +51 −18 src/type-generator.cpp
  35. +43 −6 src/types.def
  36. +4 −2 test/test.sh
View
2  classpath/avian/Addendum.java
@@ -12,5 +12,5 @@
public class Addendum {
public Object pool;
- public Object annotationTable;
+ public Object annotationTable;
}
View
268 classpath/avian/Classes.java
@@ -0,0 +1,268 @@
+/* Copyright (c) 2010, Avian Contributors
+
+ Permission to use, copy, modify, and/or distribute this software
+ for any purpose with or without fee is hereby granted, provided
+ that the above copyright notice and this permission notice appear
+ in all copies.
+
+ There is NO WARRANTY for this software. See license.txt for
+ details. */
+
+package avian;
+
+import static avian.Stream.read1;
+import static avian.Stream.read2;
+
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Method;
+import java.lang.reflect.Field;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class Classes {
+ private static final int LinkFlag = 1 << 8;
+
+ public static native VMClass defineVMClass
+ (ClassLoader loader, byte[] b, int offset, int length);
+
+ public static native VMClass vmClass(Object o);
+
+ public static native VMClass primitiveClass(char name);
+
+ public static native void initialize(VMClass vmClass);
+
+ public static native boolean isAssignableFrom(VMClass a, VMClass b);
+
+ public static native VMClass getVMClass(Object o);
+
+ private static native VMClass resolveVMClass(ClassLoader loader, byte[] spec)
+ throws ClassNotFoundException;
+
+ private static VMClass loadVMClass(ClassLoader loader,
+ byte[] nameBytes, int offset, int length)
+ {
+ byte[] spec = new byte[length + 1];
+ System.arraycopy(nameBytes, offset, spec, 0, length);
+
+ try {
+ VMClass c = resolveVMClass(loader, spec);
+ if (c == null) {
+ throw new NoClassDefFoundError();
+ }
+ return c;
+ } catch (ClassNotFoundException e) {
+ NoClassDefFoundError error = new NoClassDefFoundError
+ (new String(nameBytes, offset, length, false));
+ error.initCause(e);
+ throw error;
+ }
+ }
+
+ private static Object parseAnnotationValue(ClassLoader loader,
+ Object pool,
+ InputStream in)
+ throws IOException
+ {
+ switch (read1(in)) {
+ case 'Z':
+ return Boolean.valueOf(Singleton.getInt(pool, read2(in) - 1) != 0);
+
+ case 'B':
+ return Byte.valueOf((byte) Singleton.getInt(pool, read2(in) - 1));
+
+ case 'C':
+ return Character.valueOf((char) Singleton.getInt(pool, read2(in) - 1));
+
+ case 'S':
+ return Short.valueOf((short) Singleton.getInt(pool, read2(in) - 1));
+
+ case 'I':
+ return Integer.valueOf(Singleton.getInt(pool, read2(in) - 1));
+
+ case 'F':
+ return Float.valueOf
+ (Float.intBitsToFloat(Singleton.getInt(pool, read2(in) - 1)));
+
+ case 'J': {
+ return Long.valueOf(Singleton.getLong(pool, read2(in) - 1));
+ }
+
+ case 'D': {
+ return Double.valueOf
+ (Double.longBitsToDouble(Singleton.getLong(pool, read2(in) - 1)));
+ }
+
+ case 's': {
+ byte[] data = (byte[]) Singleton.getObject(pool, read2(in) - 1);
+
+ return new String(data, 0, data.length - 1, false);
+ }
+
+ case 'e': {
+ byte[] typeName = (byte[]) Singleton.getObject(pool, read2(in) - 1);
+ byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1);
+
+ return Enum.valueOf
+ (getClass(loadVMClass(loader, typeName, 1, typeName.length - 3)),
+ new String(name, 0, name.length - 1, false));
+ }
+
+ case 'c':{
+ byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1);
+
+ return getClass(loadVMClass(loader, name, 1, name.length - 3));
+ }
+
+ case '@':
+ return parseAnnotation(loader, pool, in);
+
+ case '[': {
+ Object[] array = new Object[read2(in)];
+ for (int i = 0; i < array.length; ++i) {
+ array[i] = parseAnnotationValue(loader, pool, in);
+ }
+ return array;
+ }
+
+ default: throw new AssertionError();
+ }
+ }
+
+ private static Object[] parseAnnotation(ClassLoader loader,
+ Object pool,
+ InputStream in)
+ throws IOException
+ {
+ byte[] typeName = (byte[]) Singleton.getObject(pool, read2(in) - 1);
+ Object[] annotation = new Object[(read2(in) + 1) * 2];
+ annotation[1] = getClass
+ (loadVMClass(loader, typeName, 1, typeName.length - 3));
+
+ for (int i = 2; i < annotation.length; i += 2) {
+ byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1);
+ annotation[i] = new String(name, 0, name.length - 1, false);
+ annotation[i + 1] = parseAnnotationValue(loader, pool, in);
+ }
+
+ return annotation;
+ }
+
+ private static Object[] parseAnnotationTable(ClassLoader loader,
+ Object pool,
+ InputStream in)
+ throws IOException
+ {
+ Object[] table = new Object[read2(in)];
+ for (int i = 0; i < table.length; ++i) {
+ table[i] = parseAnnotation(loader, pool, in);
+ }
+ return table;
+ }
+
+ private static void parseAnnotationTable(ClassLoader loader,
+ Addendum addendum)
+ {
+ if (addendum != null && addendum.annotationTable instanceof byte[]) {
+ try {
+ addendum.annotationTable = parseAnnotationTable
+ (loader, addendum.pool, new ByteArrayInputStream
+ ((byte[]) addendum.annotationTable));
+ } catch (IOException e) {
+ AssertionError error = new AssertionError();
+ error.initCause(e);
+ throw error;
+ }
+ }
+ }
+
+ private static int resolveSpec(ClassLoader loader, byte[] spec, int start) {
+ int result;
+ int end;
+ switch (spec[start]) {
+ case 'L':
+ ++ start;
+ end = start;
+ while (spec[end] != ';') ++ end;
+ result = end + 1;
+ break;
+
+ case '[':
+ end = start + 1;
+ while (spec[end] == '[') ++ end;
+ switch (spec[end]) {
+ case 'L':
+ ++ end;
+ while (spec[end] != ';') ++ end;
+ ++ end;
+ break;
+
+ default:
+ ++ end;
+ }
+ result = end;
+ break;
+
+ default:
+ return start + 1;
+ }
+
+ loadVMClass(loader, spec, start, end - start);
+
+ return result;
+ }
+
+ public static void link(VMClass c, ClassLoader loader) {
+ acquireClassLock();
+ try {
+ if ((c.vmFlags & LinkFlag) == 0) {
+ if (c.super_ != null) {
+ link(c.super_, loader);
+ }
+
+ parseAnnotationTable(loader, c.addendum);
+
+ if (c.interfaceTable != null) {
+ int stride = ((c.flags & Modifier.INTERFACE) != 0 ? 1 : 2);
+ for (int i = 0; i < c.interfaceTable.length; i += stride) {
+ link((VMClass) c.interfaceTable[i], loader);
+ }
+ }
+
+ if (c.methodTable != null) {
+ for (int i = 0; i < c.methodTable.length; ++i) {
+ VMMethod m = c.methodTable[i];
+
+ for (int j = 1; j < m.spec.length;) {
+ j = resolveSpec(loader, m.spec, j);
+ }
+
+ parseAnnotationTable(loader, m.addendum);
+ }
+ }
+
+ if (c.fieldTable != null) {
+ for (int i = 0; i < c.fieldTable.length; ++i) {
+ VMField f = c.fieldTable[i];
+
+ resolveSpec(loader, f.spec, 0);
+
+ parseAnnotationTable(loader, f.addendum);
+ }
+ }
+
+ c.vmFlags |= LinkFlag;
+ }
+ } finally {
+ releaseClassLock();
+ }
+ }
+
+ public static void link(VMClass c) {
+ link(c, c.loader);
+ }
+
+ private static native void acquireClassLock();
+
+ private static native void releaseClassLock();
+}
View
13 classpath/avian/FieldAddendum.java
@@ -0,0 +1,13 @@
+/* Copyright (c) 2010, Avian Contributors
+
+ Permission to use, copy, modify, and/or distribute this software
+ for any purpose with or without fee is hereby granted, provided
+ that the above copyright notice and this permission notice appear
+ in all copies.
+
+ There is NO WARRANTY for this software. See license.txt for
+ details. */
+
+package avian;
+
+public class FieldAddendum extends Addendum { }
View
15 classpath/avian/MethodAddendum.java
@@ -0,0 +1,15 @@
+/* Copyright (c) 2009-2010, Avian Contributors
+
+ Permission to use, copy, modify, and/or distribute this software
+ for any purpose with or without fee is hereby granted, provided
+ that the above copyright notice and this permission notice appear
+ in all copies.
+
+ There is NO WARRANTY for this software. See license.txt for
+ details. */
+
+package avian;
+
+public class MethodAddendum extends Addendum {
+ public Object exceptionTable;
+}
View
276 classpath/avian/SystemClassLoader.java
@@ -10,24 +10,10 @@
package avian;
-import static avian.Stream.read1;
-import static avian.Stream.read2;
-
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Method;
-import java.lang.reflect.Field;
import java.net.URL;
import java.net.MalformedURLException;
-import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
public class SystemClassLoader extends ClassLoader {
- private static final int LinkFlag = 1 << 8;
-
- public static native VMClass defineVMClass
- (ClassLoader loader, byte[] b, int offset, int length);
-
private static native VMClass findVMClass(String name)
throws ClassNotFoundException;
@@ -35,6 +21,8 @@ protected Class findClass(String name) throws ClassNotFoundException {
return getClass(findVMClass(name));
}
+ public static native Class getClass(VMClass vmClass);
+
private static native VMClass findLoadedVMClass(String name);
protected Class reallyFindLoadedClass(String name){
@@ -44,9 +32,6 @@ protected Class reallyFindLoadedClass(String name){
private static native boolean resourceExists(String name);
- private static native VMClass resolveVMClass(ClassLoader loader, byte[] spec)
- throws ClassNotFoundException;
-
protected URL findResource(String name) {
if (resourceExists(name)) {
try {
@@ -55,261 +40,4 @@ protected URL findResource(String name) {
}
return null;
}
-
- private static VMClass loadVMClass(ClassLoader loader,
- byte[] nameBytes, int offset, int length)
- {
- byte[] spec = new byte[length + 1];
- System.arraycopy(nameBytes, offset, spec, 0, length);
-
- try {
- VMClass c = resolveVMClass(loader, spec);
- if (c == null) {
- throw new NoClassDefFoundError();
- }
- return c;
- } catch (ClassNotFoundException e) {
- NoClassDefFoundError error = new NoClassDefFoundError
- (new String(nameBytes, offset, length, false));
- error.initCause(e);
- throw error;
- }
- }
-
- private static Object parseAnnotationValue(ClassLoader loader,
- Object pool,
- InputStream in)
- throws IOException
- {
- switch (read1(in)) {
- case 'Z':
- return Boolean.valueOf(Singleton.getInt(pool, read2(in) - 1) != 0);
-
- case 'B':
- return Byte.valueOf((byte) Singleton.getInt(pool, read2(in) - 1));
-
- case 'C':
- return Character.valueOf((char) Singleton.getInt(pool, read2(in) - 1));
-
- case 'S':
- return Short.valueOf((short) Singleton.getInt(pool, read2(in) - 1));
-
- case 'I':
- return Integer.valueOf(Singleton.getInt(pool, read2(in) - 1));
-
- case 'F':
- return Float.valueOf
- (Float.intBitsToFloat(Singleton.getInt(pool, read2(in) - 1)));
-
- case 'J': {
- return Long.valueOf(Singleton.getLong(pool, read2(in) - 1));
- }
-
- case 'D': {
- return Double.valueOf
- (Double.longBitsToDouble(Singleton.getLong(pool, read2(in) - 1)));
- }
-
- case 's': {
- byte[] data = (byte[]) Singleton.getObject(pool, read2(in) - 1);
-
- return new String(data, 0, data.length - 1, false);
- }
-
- case 'e': {
- byte[] typeName = (byte[]) Singleton.getObject(pool, read2(in) - 1);
- byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1);
-
- return Enum.valueOf
- (getClass(loadVMClass(loader, typeName, 1, typeName.length - 3)),
- new String(name, 0, name.length - 1, false));
- }
-
- case 'c':{
- byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1);
-
- return getClass(loadVMClass(loader, name, 1, name.length - 3));
- }
-
- case '@':
- return parseAnnotation(loader, pool, in);
-
- case '[': {
- Object[] array = new Object[read2(in)];
- for (int i = 0; i < array.length; ++i) {
- array[i] = parseAnnotationValue(loader, pool, in);
- }
- return array;
- }
-
- default: throw new AssertionError();
- }
- }
-
- private static Object[] parseAnnotation(ClassLoader loader,
- Object pool,
- InputStream in)
- throws IOException
- {
- byte[] typeName = (byte[]) Singleton.getObject(pool, read2(in) - 1);
- Object[] annotation = new Object[(read2(in) + 1) * 2];
- annotation[1] = getClass
- (loadVMClass(loader, typeName, 1, typeName.length - 3));
-
- for (int i = 2; i < annotation.length; i += 2) {
- byte[] name = (byte[]) Singleton.getObject(pool, read2(in) - 1);
- annotation[i] = new String(name, 0, name.length - 1, false);
- annotation[i + 1] = parseAnnotationValue(loader, pool, in);
- }
-
- return annotation;
- }
-
- private static Object[] parseAnnotationTable(ClassLoader loader,
- Object pool,
- InputStream in)
- throws IOException
- {
- Object[] table = new Object[read2(in)];
- for (int i = 0; i < table.length; ++i) {
- table[i] = parseAnnotation(loader, pool, in);
- }
- return table;
- }
-
- private static void parseAnnotationTable(ClassLoader loader,
- Addendum addendum)
- {
- if (addendum != null && addendum.annotationTable instanceof byte[]) {
- try {
- addendum.annotationTable = parseAnnotationTable
- (loader, addendum.pool, new ByteArrayInputStream
- ((byte[]) addendum.annotationTable));
- } catch (IOException e) {
- AssertionError error = new AssertionError();
- error.initCause(e);
- throw error;
- }
-
- addendum.pool = null;
- }
- }
-
- private static int resolveSpec(ClassLoader loader, byte[] spec, int start) {
- int result;
- int end;
- switch (spec[start]) {
- case 'L':
- ++ start;
- end = start;
- while (spec[end] != ';') ++ end;
- result = end + 1;
- break;
-
- case '[':
- end = start + 1;
- while (spec[end] == '[') ++ end;
- switch (spec[end]) {
- case 'L':
- ++ end;
- while (spec[end] != ';') ++ end;
- ++ end;
- break;
-
- default:
- ++ end;
- }
- result = end;
- break;
-
- default:
- return start + 1;
- }
-
- loadVMClass(loader, spec, start, end - start);
-
- return result;
- }
-
- private static native void acquireClassLock();
-
- private static native void releaseClassLock();
-
- public static Class getClass(VMClass vmClass) {
- if (vmClass.addendum == null) {
- SystemClassLoader.acquireClassLock();
- try {
- if (vmClass.addendum == null) {
- vmClass.addendum = new ClassAddendum();
- }
- } finally {
- SystemClassLoader.releaseClassLock();
- }
- }
-
- if (vmClass.addendum.class_ == null) {
- SystemClassLoader.acquireClassLock();
- try {
- if (vmClass.addendum.class_ == null) {
- vmClass.addendum.class_ = new Class(vmClass);
- }
- } finally {
- SystemClassLoader.releaseClassLock();
- }
- }
-
- return vmClass.addendum.class_;
- }
-
- public static native VMClass getVMClass(Object o);
-
- public static void link(VMClass c, ClassLoader loader) {
- acquireClassLock();
- try {
- if ((c.vmFlags & LinkFlag) == 0) {
- if (c.super_ != null) {
- link(c.super_, loader);
- }
-
- parseAnnotationTable(loader, c.addendum);
-
- if (c.interfaceTable != null) {
- int stride = ((c.flags & Modifier.INTERFACE) != 0 ? 1 : 2);
- for (int i = 0; i < c.interfaceTable.length; i += stride) {
- link((VMClass) c.interfaceTable[i], loader);
- }
- }
-
- if (c.methodTable != null) {
- for (int i = 0; i < c.methodTable.length; ++i) {
- VMMethod m = c.methodTable[i];
-
- for (int j = 1; j < m.spec.length;) {
- j = resolveSpec(loader, m.spec, j);
- }
-
- parseAnnotationTable(loader, m.addendum);
- }
- }
-
- if (c.fieldTable != null) {
- for (int i = 0; i < c.fieldTable.length; ++i) {
- VMField f = c.fieldTable[i];
-
- resolveSpec(loader, f.spec, 0);
-
- parseAnnotationTable(loader, f.addendum);
- }
- }
-
- c.vmFlags |= LinkFlag;
- }
- } finally {
- releaseClassLock();
- }
- }
-
- public static void link(VMClass c) {
- link(c, c.loader);
- }
}
View
2  classpath/avian/VMField.java
@@ -17,6 +17,6 @@
public short offset;
public byte[] name;
public byte[] spec;
- public avian.Addendum addendum;
+ public FieldAddendum addendum;
public VMClass class_;
}
View
2  classpath/avian/VMMethod.java
@@ -20,7 +20,7 @@
public int nativeID;
public byte[] name;
public byte[] spec;
- public avian.Addendum addendum;
+ public MethodAddendum addendum;
public VMClass class_;
public Object code;
}
View
4 classpath/avian/resource/Handler.java
@@ -34,6 +34,10 @@ public int getContentLength() {
public InputStream getInputStream() throws IOException {
return new ResourceInputStream(url.getFile());
}
+
+ public void connect() {
+ // ignore
+ }
}
private static class ResourceInputStream extends InputStream {
View
1  classpath/java-lang.cpp
@@ -11,7 +11,6 @@
#include "math.h"
#include "stdlib.h"
#include "time.h"
-#include "time.h"
#include "string.h"
#include "stdio.h"
#include "jni.h"
View
60 classpath/java/lang/Class.java
@@ -47,8 +47,6 @@ public Class(VMClass vmClass) {
this.vmClass = vmClass;
}
- public static native VMClass vmClass(Object o);
-
public String toString() {
return getName();
}
@@ -71,23 +69,23 @@ public String getName() {
public static String getName(VMClass c) {
if (c.name == null) {
if ((c.vmFlags & PrimitiveFlag) != 0) {
- if (c == primitiveClass('V')) {
+ if (c == SystemClassLoader.primitiveClass('V')) {
c.name = "void\0".getBytes();
- } else if (c == primitiveClass('Z')) {
+ } else if (c == SystemClassLoader.primitiveClass('Z')) {
c.name = "boolean\0".getBytes();
- } else if (c == primitiveClass('B')) {
+ } else if (c == SystemClassLoader.primitiveClass('B')) {
c.name = "byte\0".getBytes();
- } else if (c == primitiveClass('C')) {
+ } else if (c == SystemClassLoader.primitiveClass('C')) {
c.name = "char\0".getBytes();
- } else if (c == primitiveClass('S')) {
+ } else if (c == SystemClassLoader.primitiveClass('S')) {
c.name = "short\0".getBytes();
- } else if (c == primitiveClass('I')) {
+ } else if (c == SystemClassLoader.primitiveClass('I')) {
c.name = "int\0".getBytes();
- } else if (c == primitiveClass('F')) {
+ } else if (c == SystemClassLoader.primitiveClass('F')) {
c.name = "float\0".getBytes();
- } else if (c == primitiveClass('J')) {
+ } else if (c == SystemClassLoader.primitiveClass('J')) {
c.name = "long\0".getBytes();
- } else if (c == primitiveClass('D')) {
+ } else if (c == SystemClassLoader.primitiveClass('D')) {
c.name = "double\0".getBytes();
} else {
throw new AssertionError();
@@ -154,15 +152,11 @@ public static Class forName(String name, boolean initialize,
Class c = loader.loadClass(name);
SystemClassLoader.link(c.vmClass, loader);
if (initialize) {
- initialize(c.vmClass);
+ SystemClassLoader.initialize(c.vmClass);
}
return c;
}
- private static native VMClass primitiveClass(char name);
-
- private static native void initialize(VMClass vmClass);
-
public static Class forCanonicalName(String name) {
return forCanonicalName(null, name);
}
@@ -175,7 +169,8 @@ public static Class forCanonicalName(ClassLoader loader, String name) {
return forName(name.substring(1, name.length() - 1), true, loader);
} else {
if (name.length() == 1) {
- return SystemClassLoader.getClass(primitiveClass(name.charAt(0)));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass(name.charAt(0)));
} else {
throw new ClassNotFoundException(name);
}
@@ -189,21 +184,29 @@ public Class getComponentType() {
if (isArray()) {
String n = getName();
if ("[Z".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('Z'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('Z'));
} else if ("[B".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('B'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('B'));
} else if ("[S".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('S'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('S'));
} else if ("[C".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('C'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('C'));
} else if ("[I".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('I'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('I'));
} else if ("[F".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('F'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('F'));
} else if ("[J".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('J'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('J'));
} else if ("[D".equals(n)) {
- return SystemClassLoader.getClass(primitiveClass('D'));
+ return SystemClassLoader.getClass
+ (SystemClassLoader.primitiveClass('D'));
}
if (vmClass.staticTable == null) throw new AssertionError();
@@ -213,10 +216,8 @@ public Class getComponentType() {
}
}
- public static native boolean isAssignableFrom(VMClass a, VMClass b);
-
public boolean isAssignableFrom(Class c) {
- return isAssignableFrom(vmClass, c.vmClass);
+ return SystemClassLoader.isAssignableFrom(vmClass, c.vmClass);
}
private static Field findField(VMClass vmClass, String name) {
@@ -533,7 +534,8 @@ public boolean isArray() {
}
public static boolean isInstance(VMClass c, Object o) {
- return o != null && isAssignableFrom(c, SystemClassLoader.getVMClass(o));
+ return o != null && SystemClassLoader.isAssignableFrom
+ (c, SystemClassLoader.getVMClass(o));
}
public boolean isInstance(Object o) {
View
2  classpath/java/lang/OutOfMemoryError.java
@@ -10,7 +10,7 @@
package java.lang;
-public class OutOfMemoryError extends Error {
+public class OutOfMemoryError extends VirtualMachineError {
public OutOfMemoryError(String message) {
super(message, null);
}
View
2  classpath/java/lang/StackTraceElement.java
@@ -56,7 +56,7 @@ public String toString() {
}
public String getClassName() {
- return class_.replace('/', '.');
+ return class_;
}
public String getMethodName() {
View
10 classpath/java/lang/ref/ReferenceQueue.java
@@ -12,13 +12,12 @@
public class ReferenceQueue<T> {
private Reference<? extends T> front;
- private Reference<? extends T> rear;
public Reference<? extends T> poll() {
Reference<? extends T> r = front;
if (front != null) {
if (front == front.jNext) {
- front = rear = null;
+ front = null;
} else {
front = front.jNext;
}
@@ -27,12 +26,11 @@
}
void add(Reference<? extends T> r) {
- r.jNext = r;
if (front == null) {
- front = r;
+ r.jNext = r;
} else {
- rear.jNext = r;
+ r.jNext = front;
}
- rear = r;
+ front = r;
}
}
View
2  classpath/java/lang/reflect/Field.java
@@ -204,7 +204,7 @@ public void set(Object instance, Object value)
} else {
throw new IllegalArgumentException
("needed " + getType() + ", got "
- + Class.getName(Class.vmClass(target)) +
+ + Class.getName(SystemClassLoader.vmClass(target)) +
" when setting " + Class.getName(vmField.class_) + "." + getName());
}
break;
View
203 makefile
@@ -1,4 +1,4 @@
-MAKEFLAGS = -s
+#MAKEFLAGS = -s
name = avian
version = 0.3
@@ -39,11 +39,17 @@ endif
ifeq ($(continuations),true)
options := $(options)-continuations
endif
+
+classpath = avian
+
+test-library-path = .
+test-executable = $(executable)
+
ifdef gnu
+ classpath = gnu
options := $(options)-gnu
- gnu-sources = $(src)/gnu.cpp
- gnu-jar = $(gnu)/share/classpath/glibj.zip
- gnu-libraries = \
+ classapth-jar = $(gnu)/share/classpath/glibj.zip
+ classpath-libraries = \
$(gnu)/lib/classpath/libjavaio.a \
$(gnu)/lib/classpath/libjavalang.a \
$(gnu)/lib/classpath/libjavalangreflect.a \
@@ -51,10 +57,20 @@ ifdef gnu
$(gnu)/lib/classpath/libjavanet.a \
$(gnu)/lib/classpath/libjavanio.a \
$(gnu)/lib/classpath/libjavautil.a
- gnu-object-dep = $(build)/gnu-object.dep
- gnu-cflags = -DBOOT_BUILTINS=\"javaio,javalang,javalangreflect,javamath,javanet,javanio,javautil\" -DAVIAN_GNU
- gnu-lflags = -lgmp
- gnu-objects = $(shell find $(build)/gnu-objects -name "*.o")
+ classpath-cflags = -DBOOT_BUILTINS=\"javaio,javalang,javalangreflect,javamath,javanet,javanio,javautil\" -DAVIAN_GNU
+ classpath-lflags = -lgmp
+endif
+ifdef openjdk
+ classpath = openjdk
+ options := $(options)-openjdk
+ ifeq ($(arch),x86_64)
+ openjdk-lib-dir = $(openjdk)/jre/lib/amd64
+ else
+ openjdk-lib-dir = $(openjdk)/jre/lib
+ endif
+ classpath-jar = $(openjdk)/jre/lib/rt.jar
+ test-library-path = $(openjdk-lib-dir):$(native-build)
+ test-executable = $(executable-dynamic)
endif
root := $(shell (cd .. && pwd))
@@ -63,13 +79,16 @@ native-build = $(build)/$(platform)-$(arch)$(options)
classpath-build = $(build)/classpath
test-build = $(build)/test
src = src
-classpath = classpath
+classpath-src = classpath
test = test
-ifdef gnu
- avian-classpath-build = $(build)/avian-classpath
+ifneq ($(classpath),avian)
+ classpath-object-dep = $(build)/classpath-object.dep
+ classpath-objects = $(shell find $(build)/classpath-objects -name "*.o")
else
- avian-classpath-build = $(classpath-build)
+ jni-sources := $(shell find $(classpath-src) -name '*.cpp')
+ jni-objects = \
+ $(call cpp-objects,$(jni-sources),$(classpath-src),$(native-build))
endif
input = List
@@ -79,12 +98,12 @@ build-cc = gcc
mflag =
ifneq ($(platform),darwin)
- ifeq ($(arch),i386)
- mflag = -m32
- endif
- ifeq ($(arch),x86_64)
- mflag = -m64
- endif
+ ifeq ($(arch),i386)
+ mflag = -m32
+ endif
+ ifeq ($(arch),x86_64)
+ mflag = -m64
+ endif
endif
cxx = $(build-cxx) $(mflag)
@@ -112,14 +131,14 @@ warnings = -Wall -Wextra -Werror -Wunused-parameter -Winit-self \
common-cflags = $(warnings) -fno-rtti -fno-exceptions -fno-omit-frame-pointer \
"-I$(JAVA_HOME)/include" -idirafter $(src) -I$(native-build) \
-D__STDC_LIMIT_MACROS -D_JNI_IMPLEMENTATION_ -DAVIAN_VERSION=\"$(version)\" \
- -DUSE_ATOMIC_OPERATIONS $(gnu-cflags)
+ -DUSE_ATOMIC_OPERATIONS $(classpath-cflags)
build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \
"-I$(JAVA_HOME)/include/linux" -I$(src) -pthread
cflags = $(build-cflags)
-common-lflags = -lm -lz $(gnu-lflags)
+common-lflags = -lm -lz $(classpath-lflags)
build-lflags =
@@ -297,9 +316,6 @@ cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(3)/%.o,$(x)))
asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(3)/%-asm.o,$(x)))
java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(3)/%.class,$(x)))
-jni-sources := $(shell find $(classpath) -name '*.cpp')
-jni-objects = $(call cpp-objects,$(jni-sources),$(classpath),$(native-build))
-
generated-code = \
$(native-build)/type-enums.cpp \
$(native-build)/type-declarations.cpp \
@@ -307,26 +323,7 @@ generated-code = \
$(native-build)/type-initializations.cpp \
$(native-build)/type-java-initializations.cpp
-vm-depends = \
- $(generated-code) \
- $(src)/allocator.h \
- $(src)/common.h \
- $(src)/system.h \
- $(src)/heap.h \
- $(src)/finder.h \
- $(src)/processor.h \
- $(src)/process.h \
- $(src)/stream.h \
- $(src)/constants.h \
- $(src)/jnienv.h \
- $(src)/machine.h \
- $(src)/util.h \
- $(src)/zone.h \
- $(src)/assembler.h \
- $(src)/compiler.h \
- $(src)/$(asm).h \
- $(src)/heapwalk.h \
- $(src)/bootimage.h
+vm-depends := $(generated-code) $(wildcard $(src)/*.h)
vm-sources = \
$(src)/$(system).cpp \
@@ -335,10 +332,10 @@ vm-sources = \
$(src)/util.cpp \
$(src)/heap.cpp \
$(src)/$(process).cpp \
+ $(src)/classpath-$(classpath).cpp \
$(src)/builtin.cpp \
$(src)/jnienv.cpp \
- $(src)/process.cpp \
- $(gnu-sources)
+ $(src)/process.cpp
vm-asm-sources = $(src)/$(asm).S
@@ -428,48 +425,37 @@ converter = $(native-build)/binaryToObject
static-library = $(native-build)/lib$(name).a
executable = $(native-build)/$(name)${exe-suffix}
-dynamic-library = $(native-build)/$(so-prefix)$(name)$(so-suffix)
+dynamic-library = $(native-build)/$(so-prefix)jvm$(so-suffix)
executable-dynamic = $(native-build)/$(name)-dynamic${exe-suffix}
-classpath-sources := $(shell find $(classpath) -name '*.java')
+ifneq ($(classpath),avian)
+ classpath-sources := \
+ $(classpath-src)/avian/Continuations.java \
+ $(classpath-src)/avian/Callback.java \
+ $(classpath-src)/avian/CallbackReceiver.java \
+ $(classpath-src)/avian/IncompatibleContinuationException.java \
+ $(classpath-src)/avian/SystemClassLoader.java \
+ $(classpath-src)/avian/Machine.java \
+ $(classpath-src)/avian/Addendum.java \
+ $(classpath-src)/avian/ClassAddendum.java \
+ $(classpath-src)/avian/MethodAddendum.java \
+ $(classpath-src)/avian/FieldAddendum.java \
+ $(classpath-src)/avian/VMClass.java \
+ $(classpath-src)/avian/VMField.java \
+ $(classpath-src)/avian/VMMethod.java \
+ $(classpath-src)/avian/resource/Handler.java
+else
+ classpath-sources := $(shell find $(classpath-src) -name '*.java')
+endif
+
classpath-classes = \
- $(call java-classes,$(classpath-sources),$(classpath),$(classpath-build))
+ $(call java-classes,$(classpath-sources),$(classpath-src),$(classpath-build))
classpath-object = $(native-build)/classpath-jar.o
classpath-dep = $(classpath-build).dep
-gnu-blacklist = \
- java/lang/AbstractStringBuffer.class \
- java/lang/reflect/Proxy.class
-
-gnu-overrides = \
+vm-classes = \
avian/*.class \
- avian/resource/*.class \
- java/lang/Class.class \
- java/lang/Enum.class \
- java/lang/InheritableThreadLocal.class \
- java/lang/Object.class \
- java/lang/StackTraceElement.class \
- java/lang/String.class \
- java/lang/String\$$*.class \
- java/lang/StringBuffer.class \
- java/lang/StringBuilder.class \
- java/lang/StringBuilder\$$*.class \
- java/lang/Thread.class \
- java/lang/Thread\$$*.class \
- java/lang/ThreadGroup.class \
- java/lang/ThreadLocal.class \
- java/lang/Throwable.class \
- java/lang/ref/PhantomReference.class \
- java/lang/ref/Reference.class \
- java/lang/ref/ReferenceQueue.class \
- java/lang/ref/SoftReference.class \
- java/lang/ref/WeakReference.class \
- java/lang/reflect/AccessibleObject.class \
- java/lang/reflect/Constructor.class \
- java/lang/reflect/Field.class \
- java/lang/reflect/Method.class \
- java/lang/reflect/Proxy.class \
- java/lang/reflect/Proxy\$$*.class
+ avian/resource/*.class
test-sources = $(wildcard $(test)/*.java)
test-classes = $(call java-classes,$(test-sources),$(test),$(test-build))
@@ -510,7 +496,7 @@ vg: build
.PHONY: test
test: build
/bin/sh $(test)/test.sh 2>/dev/null \
- $(executable) $(mode) "$(flags)" \
+ $(test-library-path) $(test-executable) $(mode) "$(flags)" \
$(call class-names,$(test-build),$(test-classes))
.PHONY: tarball
@@ -549,27 +535,20 @@ $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep)
$(native-build)/type-generator.o: \
$(generator-headers)
-$(classpath-build)/%.class: $(classpath)/%.java
+$(classpath-build)/%.class: $(classpath-src)/%.java
@echo $(<)
-$(classpath-dep): $(classpath-sources) $(gnu-jar)
+$(classpath-dep): $(classpath-sources) $(classpath-jar)
@echo "compiling classpath classes"
- @mkdir -p $(avian-classpath-build)
- $(javac) -d $(avian-classpath-build) \
- -bootclasspath $(avian-classpath-build) \
- $(shell $(MAKE) -s --no-print-directory $(classpath-classes))
-ifdef gnu
- (wd=$$(pwd) && \
- cd $(avian-classpath-build) && \
- $(jar) c0f "$$($(native-path) "$${wd}/$(build)/overrides.jar")" \
- $(gnu-overrides))
@mkdir -p $(classpath-build)
+ifneq ($(classpath),avian)
(wd=$$(pwd) && \
cd $(classpath-build) && \
- $(jar) xf $(gnu-jar) && \
- rm $(gnu-blacklist) && \
- jar xf "$$($(native-path) "$${wd}/$(build)/overrides.jar")")
+ $(jar) xf $(classpath-jar))
endif
+ $(javac) -d $(classpath-build) \
+ -bootclasspath $(classpath-build) \
+ $(shell $(MAKE) -s --no-print-directory $(classpath-classes))
@touch $(@)
$(test-build)/%.class: $(test)/%.java
@@ -625,7 +604,7 @@ $(driver-object): $(driver-source)
$(driver-dynamic-object): $(driver-source)
@echo "compiling $(@)"
@mkdir -p $(dir $(@))
- $(cxx) $(cflags) -DBOOT_LIBRARY=\"$(so-prefix)$(name)$(so-suffix)\" \
+ $(cxx) $(cflags) -DBOOT_LIBRARY=\"$(so-prefix)jvm$(so-suffix)\" \
-c $(<) $(call output,$(@))
$(boot-object): $(boot-source)
@@ -668,14 +647,14 @@ $(generator-objects): $(native-build)/%.o: $(src)/%.cpp
$(build-cxx) -DPOINTER_SIZE=$(pointer-size) -O0 -g3 $(build-cflags) \
-c $(<) -o $(@)
-$(jni-objects): $(native-build)/%.o: $(classpath)/%.cpp
+$(jni-objects): $(native-build)/%.o: $(classpath-src)/%.cpp
$(compile-object)
-$(static-library): $(gnu-object-dep)
+$(static-library): $(classpath-object-dep)
$(static-library): $(vm-objects) $(jni-objects) $(vm-heapwalk-objects)
@echo "creating $(@)"
rm -rf $(@)
- $(ar) cru $(@) $(^) $(call gnu-objects)
+ $(ar) cru $(@) $(^) $(call classpath-objects)
$(ranlib) $(@)
$(bootimage-bin): $(bootimage-generator)
@@ -687,13 +666,13 @@ $(bootimage-object): $(bootimage-bin) $(converter)
_binary_bootimage_bin_end $(platform) $(arch) $(pointer-size) \
writable executable
-$(gnu-object-dep): $(gnu-libraries)
- @mkdir -p $(build)/gnu-objects
- (cd $(build)/gnu-objects && \
- for x in $(gnu-libraries); do ar x $${x}; done)
+$(classpath-object-dep): $(classpath-libraries)
+ @mkdir -p $(build)/classpath-objects
+ (cd $(build)/classpath-objects && \
+ for x in $(classpath-libraries); do ar x $${x}; done)
@touch $(@)
-$(executable): $(gnu-object-dep)
+$(executable): $(classpath-object-dep)
$(executable): \
$(vm-objects) $(jni-objects) $(driver-object) $(vm-heapwalk-objects) \
$(boot-object) $(vm-classpath-object)
@@ -704,13 +683,13 @@ ifdef msvc
-MANIFESTFILE:$(@).manifest
$(mt) -manifest $(@).manifest -outputresource:"$(@);1"
else
- $(dlltool) -z $(@).def $(^) $(call gnu-objects)
+ $(dlltool) -z $(@).def $(^) $(call classpath-objects)
$(dlltool) -d $(@).def -e $(@).exp
- $(ld) $(@).exp $(^) $(call gnu-objects) $(lflags) -o $(@)
+ $(ld) $(@).exp $(^) $(call classpath-objects) $(lflags) -o $(@)
endif
else
- $(ld) $(^) $(call gnu-objects) $(rdynamic) $(lflags) $(bootimage-lflags) \
- -o $(@)
+ $(ld) $(^) $(call classpath-objects) $(rdynamic) $(lflags) \
+ $(bootimage-lflags) -o $(@)
endif
$(strip) $(strip-all) $(@)
@@ -740,18 +719,18 @@ else
$(ld) $(^) $(rdynamic) $(lflags) -o $(@)
endif
-$(dynamic-library): $(gnu-object-dep)
+$(dynamic-library): $(classpath-object-dep)
$(dynamic-library): \
$(vm-objects) $(dynamic-object) $(jni-objects) $(vm-heapwalk-objects) \
- $(boot-object) $(vm-classpath-object) $(gnu-libraries)
+ $(boot-object) $(vm-classpath-object) $(classpath-libraries)
@echo "linking $(@)"
ifdef msvc
$(ld) $(shared) $(lflags) $(^) -out:$(@) -PDB:$(@).pdb \
-IMPLIB:$(native-build)/$(name).lib -MANIFESTFILE:$(@).manifest
$(mt) -manifest $(@).manifest -outputresource:"$(@);2"
else
- $(ld) $(^) $(call gnu-objects) $(shared) $(lflags) $(bootimage-lflags) \
- -o $(@)
+ $(ld) $(^) -Wl,--version-script=openjdk.ld \
+ $(call classpath-objects) $(shared) $(lflags) $(bootimage-lflags) -o $(@)
endif
$(strip) $(strip-all) $(@)
View
288 openjdk.ld
@@ -0,0 +1,288 @@
+#
+# @(#)mapfile-vers-product 1.19 08/02/12 10:56:37
+#
+
+#
+# Copyright 2002-2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+#
+
+# Define public interface.
+
+SUNWprivate_1.1 {
+ global:
+ # JNI
+ JNI_CreateJavaVM;
+ JNI_GetCreatedJavaVMs;
+ JNI_GetDefaultJavaVMInitArgs;
+
+ # JVM
+ JVM_Accept;
+ JVM_ActiveProcessorCount;
+ JVM_AllocateNewArray;
+ JVM_AllocateNewObject;
+ JVM_ArrayCopy;
+ JVM_AssertionStatusDirectives;
+ JVM_Available;
+ JVM_Bind;
+ JVM_ClassDepth;
+ JVM_ClassLoaderDepth;
+ JVM_Clone;
+ JVM_Close;
+ JVM_CX8Field;
+ JVM_CompileClass;
+ JVM_CompileClasses;
+ JVM_CompilerCommand;
+ JVM_Connect;
+ JVM_ConstantPoolGetClassAt;
+ JVM_ConstantPoolGetClassAtIfLoaded;
+ JVM_ConstantPoolGetDoubleAt;
+ JVM_ConstantPoolGetFieldAt;
+ JVM_ConstantPoolGetFieldAtIfLoaded;
+ JVM_ConstantPoolGetFloatAt;
+ JVM_ConstantPoolGetIntAt;
+ JVM_ConstantPoolGetLongAt;
+ JVM_ConstantPoolGetMethodAt;
+ JVM_ConstantPoolGetMethodAtIfLoaded;
+ JVM_ConstantPoolGetMemberRefInfoAt;
+ JVM_ConstantPoolGetSize;
+ JVM_ConstantPoolGetStringAt;
+ JVM_ConstantPoolGetUTF8At;
+ JVM_CountStackFrames;
+ JVM_CurrentClassLoader;
+ JVM_CurrentLoadedClass;
+ JVM_CurrentThread;
+ JVM_CurrentTimeMillis;
+ JVM_DefineClass;
+ JVM_DefineClassWithSource;
+ JVM_DesiredAssertionStatus;
+ JVM_DisableCompiler;
+ JVM_DoPrivileged;
+ JVM_DTraceGetVersion;
+ JVM_DTraceActivate;
+ JVM_DTraceIsProbeEnabled;
+ JVM_DTraceIsSupported;
+ JVM_DTraceDispose;
+ JVM_DumpAllStacks;
+ JVM_DumpThreads;
+ JVM_EnableCompiler;
+ JVM_Exit;
+ JVM_FillInStackTrace;
+ JVM_FindClassFromClass;
+ JVM_FindClassFromClassLoader;
+ JVM_FindClassFromBootLoader;
+ JVM_FindLibraryEntry;
+ JVM_FindLoadedClass;
+ JVM_FindPrimitiveClass;
+ JVM_FindSignal;
+ JVM_FreeMemory;
+ JVM_GC;
+ JVM_GetAllThreads;
+ JVM_GetArrayElement;
+ JVM_GetArrayLength;
+ JVM_GetCPClassNameUTF;
+ JVM_GetCPFieldClassNameUTF;
+ JVM_GetCPFieldModifiers;
+ JVM_GetCPFieldNameUTF;
+ JVM_GetCPFieldSignatureUTF;
+ JVM_GetCPMethodClassNameUTF;
+ JVM_GetCPMethodModifiers;
+ JVM_GetCPMethodNameUTF;
+ JVM_GetCPMethodSignatureUTF;
+ JVM_GetCallerClass;
+ JVM_GetClassAccessFlags;
+ JVM_GetClassAnnotations;
+ JVM_GetClassCPEntriesCount;
+ JVM_GetClassCPTypes;
+ JVM_GetClassConstantPool;
+ JVM_GetClassContext;
+ JVM_GetClassDeclaredConstructors;
+ JVM_GetClassDeclaredFields;
+ JVM_GetClassDeclaredMethods;
+ JVM_GetClassFieldsCount;
+ JVM_GetClassInterfaces;
+ JVM_GetClassLoader;
+ JVM_GetClassMethodsCount;
+ JVM_GetClassModifiers;
+ JVM_GetClassName;
+ JVM_GetClassNameUTF;
+ JVM_GetClassSignature;
+ JVM_GetClassSigners;
+ JVM_GetComponentType;
+ JVM_GetDeclaredClasses;
+ JVM_GetDeclaringClass;
+ JVM_GetEnclosingMethodInfo;
+ JVM_GetFieldAnnotations;
+ JVM_GetFieldIxModifiers;
+ JVM_GetHostName;
+ JVM_GetInheritedAccessControlContext;
+ JVM_GetInterfaceVersion;
+ JVM_GetLastErrorString;
+ JVM_GetManagement;
+ JVM_GetMethodAnnotations;
+ JVM_GetMethodDefaultAnnotationValue;
+ JVM_GetMethodIxArgsSize;
+ JVM_GetMethodIxByteCode;
+ JVM_GetMethodIxByteCodeLength;
+ JVM_GetMethodIxExceptionIndexes;
+ JVM_GetMethodIxExceptionTableEntry;
+ JVM_GetMethodIxExceptionTableLength;
+ JVM_GetMethodIxExceptionsCount;
+ JVM_GetMethodIxLocalsCount;
+ JVM_GetMethodIxMaxStack;
+ JVM_GetMethodIxModifiers;
+ JVM_GetMethodIxNameUTF;
+ JVM_GetMethodIxSignatureUTF;
+ JVM_GetMethodParameterAnnotations;
+ JVM_GetPrimitiveArrayElement;
+ JVM_GetProtectionDomain;
+ JVM_GetSockName;
+ JVM_GetSockOpt;
+ JVM_GetStackAccessControlContext;
+ JVM_GetStackTraceDepth;
+ JVM_GetStackTraceElement;
+ JVM_GetSystemPackage;
+ JVM_GetSystemPackages;
+ JVM_GetThreadStateNames;
+ JVM_GetThreadStateValues;
+ JVM_GetVersionInfo;
+ JVM_Halt;
+ JVM_HoldsLock;
+ JVM_IHashCode;
+ JVM_InitAgentProperties;
+ JVM_InitProperties;
+ JVM_InitializeCompiler;
+ JVM_InitializeSocketLibrary;
+ JVM_InternString;
+ JVM_Interrupt;
+ JVM_InvokeMethod;
+ JVM_IsArrayClass;
+ JVM_IsConstructorIx;
+ JVM_IsInterface;
+ JVM_IsInterrupted;
+ JVM_IsNaN;
+ JVM_IsPrimitiveClass;
+ JVM_IsSameClassPackage;
+ JVM_IsSilentCompiler;
+ JVM_IsSupportedJNIVersion;
+ JVM_IsThreadAlive;
+ JVM_LatestUserDefinedLoader;
+ JVM_Listen;
+ JVM_LoadClass0;
+ JVM_LoadLibrary;
+ JVM_Lseek;
+ JVM_MaxObjectInspectionAge;
+ JVM_MaxMemory;
+ JVM_MonitorNotify;
+ JVM_MonitorNotifyAll;
+ JVM_MonitorWait;
+ JVM_NanoTime;
+ JVM_NativePath;
+ JVM_NewArray;
+ JVM_NewInstanceFromConstructor;
+ JVM_NewMultiArray;
+ JVM_OnExit;
+ JVM_Open;
+ JVM_PrintStackTrace;
+ JVM_RaiseSignal;
+ JVM_RawMonitorCreate;
+ JVM_RawMonitorDestroy;
+ JVM_RawMonitorEnter;
+ JVM_RawMonitorExit;
+ JVM_Read;
+ JVM_Recv;
+ JVM_RecvFrom;
+ JVM_RegisterSignal;
+ JVM_ReleaseUTF;
+ JVM_ResolveClass;
+ JVM_ResumeThread;
+ JVM_Send;
+ JVM_SendTo;
+ JVM_SetArrayElement;
+ JVM_SetClassSigners;
+ JVM_SetLength;
+ JVM_SetPrimitiveArrayElement;
+ JVM_SetProtectionDomain;
+ JVM_SetSockOpt;
+ JVM_SetThreadPriority;
+ JVM_Sleep;
+ JVM_Socket;
+ JVM_SocketAvailable;
+ JVM_SocketClose;
+ JVM_SocketShutdown;
+ JVM_StartThread;
+ JVM_StopThread;
+ JVM_SuspendThread;
+ JVM_SupportsCX8;
+ JVM_Sync;
+ JVM_Timeout;
+ JVM_TotalMemory;
+ JVM_TraceInstructions;
+ JVM_TraceMethodCalls;
+ JVM_UnloadLibrary;
+ JVM_Write;
+ JVM_Yield;
+ JVM_handle_linux_signal;
+
+ # Old reflection routines
+ # These do not need to be present in the product build in JDK 1.4
+ # but their code has not been removed yet because there will not
+ # be a substantial code savings until JVM_InvokeMethod and
+ # JVM_NewInstanceFromConstructor can also be removed; see
+ # reflectionCompat.hpp.
+ JVM_GetClassConstructor;
+ JVM_GetClassConstructors;
+ JVM_GetClassField;
+ JVM_GetClassFields;
+ JVM_GetClassMethod;
+ JVM_GetClassMethods;
+ JVM_GetField;
+ JVM_GetPrimitiveField;
+ JVM_NewInstance;
+ JVM_SetField;
+ JVM_SetPrimitiveField;
+
+ # Needed for dropping VM into JDK 1.3.x, 1.4
+ _JVM_native_threads;
+ jdk_sem_init;
+ jdk_sem_post;
+ jdk_sem_wait;
+ jdk_pthread_sigmask;
+ jdk_waitpid;
+
+ # miscellaneous functions
+ jio_fprintf;
+ jio_printf;
+ jio_snprintf;
+ jio_vfprintf;
+ jio_vsnprintf;
+ fork1;
+ numa_warn;
+ numa_error;
+
+ # Needed because there is no JVM interface for this.
+ sysThreadAvailableStackWithSlack;
+
+ # This is for Forte Analyzer profiling support.
+ AsyncGetCallTrace;
+};
+
View
767 src/builtin.cpp
@@ -39,135 +39,14 @@ search(Thread* t, object name, object (*op)(Thread*, object),
return reinterpret_cast<int64_t>(r);
} else {
- t->exception = makeNullPointerException(t);
+ t->exception = t->m->classpath->makeThrowable
+ (t, Machine::NullPointerExceptionType);
return 0;
}
}
-void
-enumerateThreads(Thread* t, Thread* x, object array, unsigned* index,
- unsigned limit)
-{
- if (*index < limit) {
- set(t, array, ArrayBody + (*index * BytesPerWord), x->javaThread);
- ++ (*index);
-
- if (x->peer) enumerateThreads(t, x->peer, array, index, limit);
-
- if (x->child) enumerateThreads(t, x->child, array, index, limit);
- }
-}
-
-bool
-compatibleArrayTypes(Thread* t, object a, object b)
-{
- return classArrayElementSize(t, a)
- and classArrayElementSize(t, b)
- and (a == b
- or (not ((classVmFlags(t, a) & PrimitiveFlag)
- or (classVmFlags(t, b) & PrimitiveFlag))));
-}
-
-void
-runOnLoadIfFound(Thread* t, System::Library* library)
-{
- void* p = library->resolve("JNI_OnLoad");
- if (p) {
- jint (JNICALL * JNI_OnLoad)(Machine*, void*);
- memcpy(&JNI_OnLoad, &p, sizeof(void*));
- JNI_OnLoad(t->m, 0);
- }
-}
-
} // namespace
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Object_toString
-(Thread* t, object, uintptr_t* arguments)
-{
- object this_ = reinterpret_cast<object>(arguments[0]);
-
- unsigned hash = objectHash(t, this_);
- object s = makeString
- (t, "%s@0x%x",
- &byteArrayBody(t, className(t, objectClass(t, this_)), 0),
- hash);
-
- return reinterpret_cast<int64_t>(s);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Object_getVMClass
-(Thread* t, object, uintptr_t* arguments)
-{
- object o = reinterpret_cast<object>(arguments[0]);
-
- return reinterpret_cast<int64_t>(objectClass(t, o));
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Object_wait
-(Thread* t, object, uintptr_t* arguments)
-{
- object this_ = reinterpret_cast<object>(arguments[0]);
- int64_t milliseconds; memcpy(&milliseconds, arguments + 1, 8);
-
- vm::wait(t, this_, milliseconds);
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Object_notify
-(Thread* t, object, uintptr_t* arguments)
-{
- object this_ = reinterpret_cast<object>(arguments[0]);
-
- notify(t, this_);
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Object_notifyAll
-(Thread* t, object, uintptr_t* arguments)
-{
- object this_ = reinterpret_cast<object>(arguments[0]);
-
- notifyAll(t, this_);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Object_hashCode
-(Thread* t, object, uintptr_t* arguments)
-{
- object this_ = reinterpret_cast<object>(arguments[0]);
-
- return objectHash(t, this_);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Object_clone
-(Thread* t, object, uintptr_t* arguments)
-{
- object o = reinterpret_cast<object>(arguments[0]);
- PROTECT(t, o);
-
- object class_ = objectClass(t, o);
- unsigned size = baseSize(t, o, class_) * BytesPerWord;
- object clone;
-
- if (classArrayElementSize(t, class_)) {
- clone = static_cast<object>(allocate(t, size, classObjectMask(t, class_)));
- memcpy(clone, o, size);
- // clear any object header flags:
- setObjectClass(t, o, objectClass(t, o));
- } else {
- clone = make(t, class_);
- memcpy(reinterpret_cast<void**>(clone) + 1,
- reinterpret_cast<void**>(o) + 1,
- size - BytesPerWord);
- }
-
- return reinterpret_cast<int64_t>(clone);
-}
-
extern "C" JNIEXPORT void JNICALL
Avian_avian_SystemClassLoader_acquireClassLock
(Thread* t, object, uintptr_t*)
@@ -195,8 +74,6 @@ Avian_avian_SystemClassLoader_defineVMClass
(Thread* t, object, uintptr_t* arguments)
{
object loader = reinterpret_cast<object>(arguments[0]);
- PROTECT(t, loader);
-
object b = reinterpret_cast<object>(arguments[1]);
int offset = arguments[2];
int length = arguments[3];
@@ -204,20 +81,9 @@ Avian_avian_SystemClassLoader_defineVMClass
uint8_t* buffer = static_cast<uint8_t*>
(t->m->heap->allocate(length));
memcpy(buffer, &byteArrayBody(t, b, offset), length);
- object c = parseClass(t, loader, buffer, length);
+ object c = defineClass(t, loader, buffer, length);
t->m->heap->free(buffer, length);
- if (c) {
- PROTECT(t, c);
- if (getClassLoaderMap(t, loader) == 0) {
- object map = makeHashMap(t, 0, 0);
- set(t, loader, ClassLoaderMap, map);
- }
-
- hashMapInsert(t, getClassLoaderMap(t, loader), className(t, c), c,
- byteArrayHash);
- }
-
return reinterpret_cast<int64_t>(c);
}
@@ -260,62 +126,21 @@ Avian_avian_SystemClassLoader_resourceExists
stringChars(t, name, RUNTIME_ARRAY_BODY(n));
return t->m->finder->exists(RUNTIME_ARRAY_BODY(n));
} else {
- t->exception = makeNullPointerException(t);
+ t->exception = t->m->classpath->makeThrowable
+ (t, Machine::NullPointerExceptionType);
return 0;
}
}
extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_io_ObjectInputStream_makeInstance
+Avian_avian_SystemClassLoader_primitiveClass
(Thread* t, object, uintptr_t* arguments)
{
- object c = reinterpret_cast<object>(arguments[0]);
-
- return reinterpret_cast<int64_t>(make(t, c));
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Class_primitiveClass
-(Thread* t, object, uintptr_t* arguments)
-{
- char name = arguments[0];
-
- switch (name) {
- case 'B':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JbyteType));
- case 'C':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JcharType));
- case 'D':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JdoubleType));
- case 'F':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JfloatType));
- case 'I':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JintType));
- case 'J':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JlongType));
- case 'S':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JshortType));
- case 'V':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JvoidType));
- case 'Z':
- return reinterpret_cast<int64_t>
- (arrayBody(t, t->m->types, Machine::JbooleanType));
- default:
- t->exception = makeIllegalArgumentException(t);
- return 0;
- }
+ return reinterpret_cast<int64_t>(primitiveClass(t, arguments[0]));
}
extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Class_initialize
+Avian_avian_SystemClassLoader_initialize
(Thread* t, object, uintptr_t* arguments)
{
object this_ = reinterpret_cast<object>(arguments[0]);
@@ -324,7 +149,7 @@ Avian_java_lang_Class_initialize
}
extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Class_isAssignableFrom
+Avian_avian_SystemClassLoader_isAssignableFrom
(Thread* t, object, uintptr_t* arguments)
{
object this_ = reinterpret_cast<object>(arguments[0]);
@@ -333,392 +158,12 @@ Avian_java_lang_Class_isAssignableFrom
if (LIKELY(that)) {
return vm::isAssignableFrom(t, this_, that);
} else {
- t->exception = makeNullPointerException(t);
+ t->exception = t->m->classpath->makeThrowable
+ (t, Machine::NullPointerExceptionType);
return 0;
}
}
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Field_getPrimitive
-(Thread* t, object, uintptr_t* arguments)
-{
- object instance = reinterpret_cast<object>(arguments[0]);
- int code = arguments[1];
- int offset = arguments[2];
-
- switch (code) {
- case ByteField:
- return cast<int8_t>(instance, offset);
- case BooleanField:
- return cast<uint8_t>(instance, offset);
- case CharField:
- return cast<uint16_t>(instance, offset);
- case ShortField:
- return cast<int16_t>(instance, offset);
- case IntField:
- return cast<int32_t>(instance, offset);
- case LongField:
- return cast<int64_t>(instance, offset);
- case FloatField:
- return cast<uint32_t>(instance, offset);
- case DoubleField:
- return cast<uint64_t>(instance, offset);
- default:
- abort(t);
- }
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Field_getObject
-(Thread*, object, uintptr_t* arguments)
-{
- object instance = reinterpret_cast<object>(arguments[0]);
- int offset = arguments[1];
-
- return reinterpret_cast<int64_t>(cast<object>(instance, offset));
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_reflect_Field_setPrimitive
-(Thread* t, object, uintptr_t* arguments)
-{
- object instance = reinterpret_cast<object>(arguments[0]);
- int code = arguments[1];
- int offset = arguments[2];
- int64_t value; memcpy(&value, arguments + 3, 8);
-
- switch (code) {
- case ByteField:
- cast<int8_t>(instance, offset) = static_cast<int8_t>(value);
- break;
- case BooleanField:
- cast<uint8_t>(instance, offset) = static_cast<uint8_t>(value);
- break;
- case CharField:
- cast<uint16_t>(instance, offset) = static_cast<uint16_t>(value);
- break;
- case ShortField:
- cast<int16_t>(instance, offset) = static_cast<int16_t>(value);
- break;
- case IntField:
- cast<int32_t>(instance, offset) = static_cast<int32_t>(value);
- break;
- case LongField:
- cast<int64_t>(instance, offset) = static_cast<int64_t>(value);
- break;
- case FloatField:
- cast<uint32_t>(instance, offset) = static_cast<uint32_t>(value);
- break;
- case DoubleField:
- cast<uint64_t>(instance, offset) = static_cast<uint64_t>(value);
- break;
- default:
- abort(t);
- }
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_reflect_Field_setObject
-(Thread* t, object, uintptr_t* arguments)
-{
- object instance = reinterpret_cast<object>(arguments[0]);
- int offset = arguments[1];
- object value = reinterpret_cast<object>(arguments[2]);
-
- set(t, instance, offset, value);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Constructor_make
-(Thread* t, object, uintptr_t* arguments)
-{
- object c = reinterpret_cast<object>(arguments[0]);
-
- return reinterpret_cast<int64_t>(make(t, c));
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Method_getCaller
-(Thread* t, object, uintptr_t*)
-{
- class Visitor: public Processor::StackVisitor {
- public:
- Visitor(Thread* t): t(t), method(0), count(0) { }
-
- virtual bool visit(Processor::StackWalker* walker) {
- if (count == 2) {
- method = walker->method();
- return false;
- } else {
- ++ count;
- return true;
- }
- }
-
- Thread* t;
- object method;
- unsigned count;
- } v(t);
-
- t->m->processor->walkStack(t, &v);
-
- return reinterpret_cast<int64_t>(v.method);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Method_invoke
-(Thread* t, object, uintptr_t* arguments)
-{
- object method = reinterpret_cast<object>(arguments[0]);
- object instance = reinterpret_cast<object>(arguments[1]);
- object args = reinterpret_cast<object>(arguments[2]);
-
- object v = t->m->processor->invokeArray(t, method, instance, args);
- if (t->exception) {
- t->exception = makeInvocationTargetException(t, t->exception);
- }
- return reinterpret_cast<int64_t>(v);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Array_getLength
-(Thread* t, object, uintptr_t* arguments)
-{
- object array = reinterpret_cast<object>(arguments[0]);
-
- if (LIKELY(array)) {
- unsigned elementSize = classArrayElementSize(t, objectClass(t, array));
-
- if (LIKELY(elementSize)) {
- return cast<uintptr_t>(array, BytesPerWord);
- } else {
- t->exception = makeIllegalArgumentException(t);
- }
- } else {
- t->exception = makeNullPointerException(t);
- }
- return 0;
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_reflect_Array_makeObjectArray
-(Thread* t, object, uintptr_t* arguments)
-{
- object elementType = reinterpret_cast<object>(arguments[0]);
- int length = arguments[1];
-
- return reinterpret_cast<int64_t>
- (makeObjectArray(t, classLoader(t, elementType), elementType, length));
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Float_floatToRawIntBits
-(Thread*, object, uintptr_t* arguments)
-{
- return static_cast<int32_t>(*arguments);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Float_intBitsToFloat
-(Thread*, object, uintptr_t* arguments)
-{
- return static_cast<int32_t>(*arguments);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Double_doubleToRawLongBits
-(Thread*, object, uintptr_t* arguments)
-{
- int64_t v; memcpy(&v, arguments, 8);
- return v;
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Double_longBitsToDouble
-(Thread*, object, uintptr_t* arguments)
-{
- int64_t v; memcpy(&v, arguments, 8);
- return v;
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_String_intern
-(Thread* t, object, uintptr_t* arguments)
-{
- object this_ = reinterpret_cast<object>(arguments[0]);
-
- return reinterpret_cast<int64_t>(intern(t, this_));
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_System_getVMProperty
-(Thread* t, object, uintptr_t* arguments)
-{
- object name = reinterpret_cast<object>(arguments[0]);
- object found = reinterpret_cast<object>(arguments[1]);
- PROTECT(t, found);
-
- unsigned length = stringLength(t, name);
- RUNTIME_ARRAY(char, n, length + 1);
- stringChars(t, name, RUNTIME_ARRAY_BODY(n));
-
- int64_t r = 0;
- if (::strcmp(RUNTIME_ARRAY_BODY(n), "java.lang.classpath") == 0) {
- r = reinterpret_cast<int64_t>(makeString(t, "%s", t->m->finder->path()));
- } else if (::strcmp(RUNTIME_ARRAY_BODY(n), "avian.version") == 0) {
- r = reinterpret_cast<int64_t>(makeString(t, AVIAN_VERSION));
- } else if (::strcmp(RUNTIME_ARRAY_BODY(n), "file.encoding") == 0) {
- r = reinterpret_cast<int64_t>(makeString(t, "ASCII"));
- } else {
- const char* v = findProperty(t, RUNTIME_ARRAY_BODY(n));
- if (v) {
- r = reinterpret_cast<int64_t>(makeString(t, v));
- }
- }
-
- if (r) {
- booleanArrayBody(t, found, 0) = true;
- }
-
- return r;
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_System_arraycopy
-(Thread* t, object, uintptr_t* arguments)
-{
- object src = reinterpret_cast<object>(arguments[0]);
- int32_t srcOffset = arguments[1];
- object dst = reinterpret_cast<object>(arguments[2]);
- int32_t dstOffset = arguments[3];
- int32_t length = arguments[4];
-
- if (LIKELY(src and dst)) {
- if (LIKELY(compatibleArrayTypes
- (t, objectClass(t, src), objectClass(t, dst))))
- {
- unsigned elementSize = classArrayElementSize(t, objectClass(t, src));
-
- if (LIKELY(elementSize)) {
- intptr_t sl = cast<uintptr_t>(src, BytesPerWord);
- intptr_t dl = cast<uintptr_t>(dst, BytesPerWord);
- if (LIKELY(length > 0)) {
- if (LIKELY(srcOffset >= 0 and srcOffset + length <= sl and
- dstOffset >= 0 and dstOffset + length <= dl))
- {
- uint8_t* sbody = &cast<uint8_t>(src, ArrayBody);
- uint8_t* dbody = &cast<uint8_t>(dst, ArrayBody);
- if (src == dst) {
- memmove(dbody + (dstOffset * elementSize),
- sbody + (srcOffset * elementSize),
- length * elementSize);
- } else {
- memcpy(dbody + (dstOffset * elementSize),
- sbody + (srcOffset * elementSize),
- length * elementSize);
- }
-
- if (classObjectMask(t, objectClass(t, dst))) {
- mark(t, dst, ArrayBody + (dstOffset * BytesPerWord), length);
- }
-
- return;
- } else {
- t->exception = makeIndexOutOfBoundsException(t);
- return;
- }
- } else {
- return;
- }
- }
- }
- } else {
- t->exception = makeNullPointerException(t);
- return;
- }
-
- t->exception = makeArrayStoreException(t);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_System_identityHashCode
-(Thread* t, object, uintptr_t* arguments)
-{
- object o = reinterpret_cast<object>(arguments[0]);
-
- if (LIKELY(o)) {
- return objectHash(t, o);
- } else {
- t->exception = makeNullPointerException(t);
- return 0;
- }
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Runtime_load
-(Thread* t, object, uintptr_t* arguments)
-{
- object name = reinterpret_cast<object>(arguments[0]);
- bool mapName = arguments[1];
-
- unsigned length = stringLength(t, name);
- RUNTIME_ARRAY(char, n, length + 1);
- stringChars(t, name, RUNTIME_ARRAY_BODY(n));
-
- ACQUIRE(t, t->m->classLock);
-
- const char* builtins = findProperty(t, "avian.builtins");
- if (mapName and builtins) {
- const char* s = builtins;
- while (*s) {
- if (::strncmp(s, RUNTIME_ARRAY_BODY(n), length) == 0
- and (s[length] == ',' or s[length] == 0))
- {
- // library is built in to this executable
- if (not t->m->triedBuiltinOnLoad) {
- t->m->triedBuiltinOnLoad = true;
- runOnLoadIfFound(t, t->m->libraries);
- }
- return;
- } else {
- while (*s and *s != ',') ++ s;
- if (*s) ++ s;
- }
- }
- }
-
- System::Library* last = t->m->libraries;
- for (System::Library* lib = t->m->libraries; lib; lib = lib->next()) {
- if (lib->name()
- and ::strcmp(lib->name(), RUNTIME_ARRAY_BODY(n)) == 0
- and lib->mapName() == mapName)
- {
- // already loaded
- return;
- }
- last = lib;
- }
-
- System::Library* lib;
- if (LIKELY(t->m->system->success
- (t->m->system->load(&lib, RUNTIME_ARRAY_BODY(n), mapName))))
- {
- last->setNext(lib);
- runOnLoadIfFound(t, lib);
- } else {
- object message = makeString
- (t, "library not found: %s", RUNTIME_ARRAY_BODY(n));
- t->exception = makeUnsatisfiedLinkError(t, message);
- }
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Runtime_gc
-(Thread* t, object, uintptr_t*)
-{
- collect(t, Heap::MajorCollection);
-}
-
#ifdef AVIAN_HEAPDUMP
extern "C" JNIEXPORT void JNICALL
@@ -754,193 +199,6 @@ Avian_java_lang_Runtime_exit
}
extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Runtime_freeMemory
-(Thread*, object, uintptr_t*)
-{
- // todo
- return 0;
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Runtime_totalMemory
-(Thread*, object, uintptr_t*)
-{
- // todo
- return 0;
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Runtime_addShutdownHook
-(Thread* t, object, uintptr_t* arguments)
-{
- object hook = reinterpret_cast<object>(arguments[1]);
- PROTECT(t, hook);
-
- ACQUIRE(t, t->m->shutdownLock);
-
- t->m->shutdownHooks = makePair(t, hook, t->m->shutdownHooks);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Throwable_trace
-(Thread* t, object, uintptr_t* arguments)
-{
- int32_t skipCount = arguments[0];
-
- class Visitor: public Processor::StackVisitor {
- public:
- Visitor(Thread* t, int skipCount):
- t(t), trace(0), skipCount(skipCount)
- { }
-
- virtual bool visit(Processor::StackWalker* walker) {
- if (skipCount == 0) {
- object method = walker->method();
- if (isAssignableFrom
- (t, arrayBody(t, t->m->types, Machine::ThrowableType),
- methodClass(t, method))
- and vm::strcmp(reinterpret_cast<const int8_t*>("<init>"),
- &byteArrayBody(t, methodName(t, method), 0))
- == 0)
- {
- return true;
- } else {
- trace = makeTrace(t, walker);
- return false;
- }
- } else {
- -- skipCount;
- return true;
- }
- }
-
- Thread* t;
- object trace;
- unsigned skipCount;
- } v(t, skipCount);
-
- t->m->processor->walkStack(t, &v);
-
- if (v.trace == 0) v.trace = makeArray(t, 0);
-
- return reinterpret_cast<int64_t>(v.trace);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Throwable_resolveTrace
-(Thread* t, object, uintptr_t* arguments)
-{
- object trace = reinterpret_cast<object>(*arguments);
- PROTECT(t, trace);
-
- unsigned length = arrayLength(t, trace);
- object elementType = arrayBody
- (t, t->m->types, Machine::StackTraceElementType);
- object array = makeObjectArray
- (t, classLoader(t, elementType), elementType, length);
- PROTECT(t, array);
-
- object e = 0;
- PROTECT(t, e);
-
- object class_ = 0;
- PROTECT(t, class_);
-
- object method = 0;
- PROTECT(t, method);
-
- for (unsigned i = 0; i < length; ++i) {
- e = arrayBody(t, trace, i);
-
- class_ = className(t, methodClass(t, traceElementMethod(t, e)));
- class_ = makeString(t, class_, 0, byteArrayLength(t, class_) - 1, 0);
-
- method = methodName(t, traceElementMethod(t, e));
- method = makeString(t, method, 0, byteArrayLength(t, method) - 1, 0);
-
- unsigned line = t->m->processor->lineNumber
- (t, traceElementMethod(t, e), traceElementIp(t, e));
-
- object file = classSourceFile(t, methodClass(t, traceElementMethod(t, e)));
- file = file ? makeString(t, file, 0, byteArrayLength(t, file) - 1, 0) : 0;
-
- object ste = makeStackTraceElement(t, class_, method, file, line);
- set(t, array, ArrayBody + (i * BytesPerWord), ste);
- }
-
- return reinterpret_cast<int64_t>(array);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Thread_currentThread
-(Thread* t, object, uintptr_t*)
-{
- return reinterpret_cast<int64_t>(t->javaThread);
-}
-
-extern "C" JNIEXPORT int64_t JNICALL
-Avian_java_lang_Thread_doStart
-(Thread* t, object, uintptr_t* arguments)
-{
- return reinterpret_cast<int64_t>
- (startThread(t, reinterpret_cast<object>(*arguments)));
-}
-
-extern "C" JNIEXPORT void JNICALL
-Avian_java_lang_Thread_interrupt
-(Thread* t, object, uintptr_t* arguments)
-{
- int64_t peer; memcpy(&peer, arguments, 8);
-
- interrupt(t, reinterpret_cast<Thread*>(peer));
-}
-