mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
flesh out ClassLoader, etc.
This commit is contained in:
@ -6,6 +6,10 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class Class <T> {
|
||||
private static final int ReferenceFlag = 1 << 0;
|
||||
private static final int WeakReferenceFlag = 1 << 1;
|
||||
private static final int NeedInitFlag = 1 << 2;
|
||||
|
||||
private short flags;
|
||||
private byte vmFlags;
|
||||
private byte arrayDimensions;
|
||||
@ -19,6 +23,7 @@ public final class Class <T> {
|
||||
private Field[] fieldTable;
|
||||
private Method[] methodTable;
|
||||
private Object[] staticTable;
|
||||
private ClassLoader loader;
|
||||
|
||||
private Class() { }
|
||||
|
||||
@ -26,8 +31,25 @@ public final class Class <T> {
|
||||
return new String(name, 0, name.length - 1, false);
|
||||
}
|
||||
|
||||
public static native Class forName(String name)
|
||||
throws ClassNotFoundException;
|
||||
public static Class forName(String name) throws ClassNotFoundException {
|
||||
return forName
|
||||
(name, true, Method.getCaller().getDeclaringClass().getClassLoader());
|
||||
}
|
||||
|
||||
public static Class forName(String name, boolean initialize,
|
||||
ClassLoader loader)
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
Class c = loader.loadClass(name);
|
||||
if (initialize && ((c.flags & NeedInitFlag) != 0)) {
|
||||
c.flags &= ~NeedInitFlag;
|
||||
Method m = c.findMethod("<clinit>", new Class[0]);
|
||||
if (m != null) {
|
||||
m.invoke(null);
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
private static native Class primitiveClass(char name);
|
||||
|
||||
@ -282,7 +304,7 @@ public final class Class <T> {
|
||||
}
|
||||
|
||||
public ClassLoader getClassLoader() {
|
||||
return ClassLoader.getSystemClassLoader();
|
||||
return loader;
|
||||
}
|
||||
|
||||
public int getModifiers() {
|
||||
|
@ -1,15 +1,78 @@
|
||||
package java.lang;
|
||||
|
||||
public class ClassLoader {
|
||||
private static final ClassLoader instance = new ClassLoader();
|
||||
public abstract class ClassLoader {
|
||||
private final ClassLoader parent;
|
||||
|
||||
private ClassLoader() { }
|
||||
protected ClassLoader(ClassLoader parent) {
|
||||
if (parent == null) {
|
||||
this.parent = getSystemClassLoader();
|
||||
} else {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
protected ClassLoader() {
|
||||
this(getSystemClassLoader());
|
||||
}
|
||||
|
||||
public static ClassLoader getSystemClassLoader() {
|
||||
return instance;
|
||||
return ClassLoader.class.getClassLoader();
|
||||
}
|
||||
|
||||
private static native Class defineClass(byte[] b, int offset, int length);
|
||||
|
||||
protected Class defineClass(String name, byte[] b, int offset, int length) {
|
||||
if (b == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
if (offset < 0 || offset > length || offset + length > b.length) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
return defineClass(b, offset, length);
|
||||
}
|
||||
|
||||
protected Class findClass(String name) throws ClassNotFoundException {
|
||||
throw new ClassNotFoundException();
|
||||
}
|
||||
|
||||
protected Class findLoadedClass(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class loadClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(name);
|
||||
return loadClass(name, false);
|
||||
}
|
||||
|
||||
protected Class loadClass(String name, boolean resolve)
|
||||
throws ClassNotFoundException
|
||||
{
|
||||
Class c = findLoadedClass(name);
|
||||
if (c == null) {
|
||||
if (parent != null) {
|
||||
try {
|
||||
c = parent.loadClass(name);
|
||||
} catch (ClassNotFoundException ok) { }
|
||||
}
|
||||
|
||||
if (c == null) {
|
||||
c = findClass(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (resolve) {
|
||||
resolveClass(c);
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
protected void resolveClass(Class c) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
private ClassLoader getParent() {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
@ -27,63 +27,27 @@ public final class Math {
|
||||
return (int) (v + 0.5);
|
||||
}
|
||||
|
||||
public static double floor(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double floor(double v);
|
||||
|
||||
public static double ceil(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double ceil(double v);
|
||||
|
||||
public static double exp(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double exp(double v);
|
||||
|
||||
public static double log(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double log(double v);
|
||||
|
||||
public static double cos(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double cos(double v);
|
||||
|
||||
public static double sin(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double sin(double v);
|
||||
|
||||
public static double tan(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double tan(double v);
|
||||
|
||||
public static double acos(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double acos(double v);
|
||||
|
||||
public static double asin(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double asin(double v);
|
||||
|
||||
public static double atan(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double atan(double v);
|
||||
|
||||
public static double sqrt(double v) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double sqrt(double v);
|
||||
|
||||
public static double pow(double v, double e) {
|
||||
// todo
|
||||
return 0;
|
||||
}
|
||||
public static native double pow(double v, double e);
|
||||
}
|
||||
|
9
classpath/java/lang/SystemClassLoader.java
Normal file
9
classpath/java/lang/SystemClassLoader.java
Normal file
@ -0,0 +1,9 @@
|
||||
package java.lang;
|
||||
|
||||
public class SystemClassLoader extends ClassLoader {
|
||||
private Object map;
|
||||
|
||||
protected native Class findClass(String name) throws ClassNotFoundException;
|
||||
|
||||
protected native Class findLoadedClass(String name);
|
||||
}
|
@ -21,6 +21,8 @@ public class Method<T> extends AccessibleObject implements Member {
|
||||
if (v) vmFlags |= Accessible; else vmFlags &= ~Accessible;
|
||||
}
|
||||
|
||||
public static native Method getCaller();
|
||||
|
||||
public Class<T> getDeclaringClass() {
|
||||
return class_;
|
||||
}
|
||||
|
Reference in New Issue
Block a user