add a bunch of classes to classpath and flesh out a few existing ones

This commit is contained in:
Joel Dice 2007-07-21 11:50:26 -06:00
parent 108f8d7bc0
commit 48226f988c
33 changed files with 475 additions and 50 deletions

View File

@ -1,6 +1,6 @@
package java.lang;
public final class Byte {
public final class Byte extends Number {
private final byte value;
public Byte(byte value) {
@ -10,4 +10,24 @@ public final class Byte {
public byte byteValue() {
return value;
}
public short shortValue() {
return value;
}
public int intValue() {
return value;
}
public long longValue() {
return value;
}
public float floatValue() {
return (float) value;
}
public double doubleValue() {
return (double) value;
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class ClassCastException extends RuntimeException {
public ClassCastException(String message) {
super(message);
}
public ClassCastException() {
super();
}
}

View File

@ -0,0 +1,5 @@
package java.lang;
public abstract class ClassLoader {
}

View File

@ -0,0 +1,15 @@
package java.lang;
public class ClassNotFoundException extends Exception {
public ClassNotFoundException(String message, Throwable cause) {
super(message, cause);
}
public ClassNotFoundException(String message) {
this(message, null);
}
public ClassNotFoundException() {
this(null, null);
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class CloneNotSupportedException extends Exception {
public CloneNotSupportedException(String message) {
super(message);
}
public CloneNotSupportedException() {
super();
}
}

View File

@ -7,6 +7,26 @@ public final class Double {
this.value = value;
}
public byte byteValue() {
return (byte) value;
}
public short shortValue() {
return (short) value;
}
public int intValue() {
return (int) value;
}
public long longValue() {
return (long) value;
}
public float floatValue() {
return (float) value;
}
public double doubleValue() {
return value;
}

View File

@ -1,13 +1,33 @@
package java.lang;
public final class Float {
public final class Float extends Number {
private final float value;
public Float(float value) {
this.value = value;
}
public byte byteValue() {
return (byte) value;
}
public short shortValue() {
return (short) value;
}
public int intValue() {
return (int) value;
}
public long longValue() {
return (long) value;
}
public float floatValue() {
return value;
}
public double doubleValue() {
return (double) value;
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class IllegalAccessException extends Exception {
public IllegalAccessException(String message) {
super(message);
}
public IllegalAccessException() {
super();
}
}

View File

@ -0,0 +1,19 @@
package java.lang;
public class IllegalArgumentException extends RuntimeException {
public IllegalArgumentException(String message, Throwable cause) {
super(message, cause);
}
public IllegalArgumentException(String message) {
this(message, null);
}
public IllegalArgumentException(Throwable cause) {
this(null, cause);
}
public IllegalArgumentException() {
this(null, null);
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class InstantiationException extends Exception {
public InstantiationException(String message) {
super(message);
}
public InstantiationException() {
super();
}
}

View File

@ -1,13 +1,33 @@
package java.lang;
public final class Integer {
public final class Integer extends Number {
private final int value;
public Integer(int value) {
this.value = value;
}
public byte byteValue() {
return (byte) value;
}
public short shortValue() {
return (short) value;
}
public int intValue() {
return value;
}
public long longValue() {
return value;
}
public float floatValue() {
return (float) value;
}
public double doubleValue() {
return (double) value;
}
}

View File

@ -1,13 +1,33 @@
package java.lang;
public final class Long {
public final class Long extends Number {
private final long value;
public Long(long value) {
this.value = value;
}
public byte byteValue() {
return (byte) value;
}
public short shortValue() {
return (short) value;
}
public int intValue() {
return (int) value;
}
public long longValue() {
return value;
}
public float floatValue() {
return (float) value;
}
public double doubleValue() {
return (double) value;
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class NoClassDefFoundError extends LinkageError {
public NoClassDefFoundError(String message) {
super(message);
}
public NoClassDefFoundError() {
super();
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class NoSuchFieldException extends Exception {
public NoSuchFieldException(String message) {
super(message);
}
public NoSuchFieldException() {
super();
}
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class NoSuchMethodException extends Exception {
public NoSuchMethodException(String message) {
super(message);
}
public NoSuchMethodException() {
super();
}
}

View File

@ -0,0 +1,10 @@
package java.lang;
public abstract class Number {
public abstract byte byteValue();
public abstract short shortValue();
public abstract int intValue();
public abstract long longValue();
public abstract float floatValue();
public abstract double doubleValue();
}

View File

@ -0,0 +1,11 @@
package java.lang;
public class NumberFormatException extends IllegalArgumentException {
public NumberFormatException(String message) {
super(message);
}
public NumberFormatException() {
super();
}
}

View File

@ -0,0 +1,17 @@
package java.lang;
public class Runtime {
private static final Runtime instance = new Runtime();
private Runtime() { }
public static Runtime getRuntime() {
return instance;
}
public native void loadLibrary(String name);
public native void gc();
public native void exit(int code);
}

View File

@ -0,0 +1,19 @@
package java.lang;
public class SecurityException extends RuntimeException {
public SecurityException(String message, Throwable cause) {
super(message, cause);
}
public SecurityException(String message) {
this(message, null);
}
public SecurityException(Throwable cause) {
this(null, cause);
}
public SecurityException() {
this(null, null);
}
}

View File

@ -1,13 +1,33 @@
package java.lang;
public final class Short {
public final class Short extends Number {
private final short value;
public Short(short value) {
this.value = value;
}
public byte byteValue() {
return (byte) value;
}
public short shortValue() {
return value;
}
public int intValue() {
return value;
}
public long longValue() {
return value;
}
public float floatValue() {
return (float) value;
}
public double doubleValue() {
return (double) value;
}
}

View File

@ -11,11 +11,19 @@ public abstract class System {
public static native void arraycopy(Object src, int srcOffset, Object dst,
int dstOffset, int length);
public static native void loadLibrary(String name);
public static native String getProperty(String name);
public static native void gc();
public static void loadLibrary(String name) {
Runtime.getRuntime().loadLibrary(name);
}
public static void gc() {
Runtime.getRuntime().gc();
}
public static void exit(int code) {
Runtime.getRuntime().exit(code);
}
public static class Output {
public synchronized native void print(String s);

View File

@ -1,9 +1,9 @@
package java.lang.ref;
public abstract class Reference<T> {
private Object vmNext;
private T target;
private ReferenceQueue<? super T> queue;
private Object vmNext;
Reference next;
protected Reference(T target, ReferenceQueue<? super T> queue) {

View File

@ -0,0 +1,9 @@
package java.lang.reflect;
public abstract class AccessibleObject {
protected static final int Accessible = 1 << 0;
public abstract boolean isAccessible();
public abstract void setAccessible(boolean v);
}

View File

@ -0,0 +1,20 @@
package java.lang.reflect;
public class Constructor<T> extends AccessibleObject {
private Method<T> method;
private Constructor() { }
public boolean equals(Object o) {
return o instanceof Constructor
&& ((Constructor) o).method.equals(method);
}
public boolean isAccessible() {
return method.isAccessible();
}
public void setAccessible(boolean v) {
method.setAccessible(v);
}
}

View File

@ -0,0 +1,21 @@
package java.lang.reflect;
public class Field<T> extends AccessibleObject {
private byte vmFlags;
private byte code;
private short flags;
private short offset;
private byte[] name;
private byte[] spec;
private Class<T> class_;
private Field() { }
public boolean isAccessible() {
return (vmFlags & Accessible) != 0;
}
public void setAccessible(boolean v) {
if (v) vmFlags |= Accessible; else vmFlags &= ~Accessible;
}
}

View File

@ -0,0 +1,23 @@
package java.lang.reflect;
public class Method<T> extends AccessibleObject {
private byte vmFlags;
private byte parameterCount;
private short parameterFootprint;
private short flags;
private short offset;
private byte[] name;
private byte[] spec;
private Class<T> class_;
private Object code;
private Method() { }
public boolean isAccessible() {
return (vmFlags & Accessible) != 0;
}
public void setAccessible(boolean v) {
if (v) vmFlags |= Accessible; else vmFlags &= ~Accessible;
}
}

View File

@ -1,4 +1,4 @@
#MAKEFLAGS = -s
MAKEFLAGS = -s
arch = $(shell uname -m)
ifeq ($(arch),i586)

View File

@ -51,28 +51,6 @@ sleep(Thread* t, jlong milliseconds)
t->vm->system->sleep(milliseconds);
}
void
loadLibrary(Thread* t, jstring nameString)
{
if (LIKELY(nameString)) {
object n = *nameString;
char name[stringLength(t, n) + 1];
stringChars(t, n, name);
System::Library* lib;
if (LIKELY(t->vm->system->success
(t->vm->system->load(&lib, name, t->vm->libraries))))
{
t->vm->libraries = lib;
} else {
object message = makeString(t, "library not found: %s", name);
t->exception = makeRuntimeException(t, message);
}
} else {
t->exception = makeNullPointerException(t);
}
}
void
arraycopy(Thread* t, jobject src, jint srcOffset, jobject dst, jint dstOffset,
jint length)
@ -108,13 +86,48 @@ arraycopy(Thread* t, jobject src, jint srcOffset, jobject dst, jint dstOffset,
}
void
gc(Thread* t)
loadLibrary(Thread* t, jobject, jstring nameString)
{
if (LIKELY(nameString)) {
object n = *nameString;
char name[stringLength(t, n) + 1];
stringChars(t, n, name);
for (System::Library* lib = t->vm->libraries; lib; lib = lib->next()) {
if (::strcmp(lib->name(), name) == 0) {
// already loaded
return;
}
}
System::Library* lib;
if (LIKELY(t->vm->system->success
(t->vm->system->load(&lib, name, t->vm->libraries))))
{
t->vm->libraries = lib;
} else {
object message = makeString(t, "library not found: %s", name);
t->exception = makeRuntimeException(t, message);
}
} else {
t->exception = makeNullPointerException(t);
}
}
void
gc(Thread* t, jobject)
{
ENTER(t, Thread::ExclusiveState);
collect(t, Heap::MajorCollection);
}
void
exit(Thread* t, jobject, jint code)
{
t->vm->system->exit(code);
}
jobject
trace(Thread* t, jint skipCount)
{
@ -224,10 +237,13 @@ populate(Thread* t, object map)
} builtins[] = {
{ "Java_java_lang_System_arraycopy",
reinterpret_cast<void*>(arraycopy) },
{ "Java_java_lang_System_loadLibrary",
{ "Java_java_lang_Runtime_loadLibrary",
reinterpret_cast<void*>(loadLibrary) },
{ "Java_java_lang_System_gc",
{ "Java_java_lang_Runtime_gc",
reinterpret_cast<void*>(gc) },
{ "Java_java_lang_Runtiime_exit",
reinterpret_cast<void*>(exit) },
{ "Java_java_lang_Thread_start",
reinterpret_cast<void*>(start) },

View File

@ -139,6 +139,9 @@ visitRoots(Thread* t, Heap::Visitor* v)
void
referenceTargetUnreachable(Thread* t, object* p, Heap::Visitor* v)
{
// fprintf(stderr, "target %p unreachable for reference %p\n",
// jreferenceTarget(t, *p), *p);
v->visit(p);
jreferenceTarget(t, *p) = 0;
@ -166,6 +169,9 @@ referenceTargetUnreachable(Thread* t, object* p, Heap::Visitor* v)
void
referenceUnreachable(Thread* t, object* p, Heap::Visitor* v)
{
// fprintf(stderr, "reference %p unreachable\n",
// *p);
if (jreferenceQueue(t, *p)
and t->vm->heap->status(jreferenceQueue(t, *p)) != Heap::Unreachable)
{
@ -177,6 +183,9 @@ referenceUnreachable(Thread* t, object* p, Heap::Visitor* v)
void
referenceTargetReachable(Thread* t, object* p, Heap::Visitor* v)
{
// fprintf(stderr, "target %p reachable for reference %p\n",
// jreferenceTarget(t, *p), *p);
v->visit(p);
v->visit(&jreferenceTarget(t, *p));
@ -711,9 +720,10 @@ parseFieldTable(Thread* t, Stream& s, object class_, object pool)
object field = makeField
(t,
0, // vm flags
fieldCode(t, byteArrayBody(t, arrayBody(t, pool, spec - 1), 0)),
flags,
0, // offset
fieldCode(t, byteArrayBody(t, arrayBody(t, pool, spec - 1), 0)),
arrayBody(t, pool, name - 1),
arrayBody(t, pool, spec - 1),
class_);
@ -914,10 +924,11 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool)
}
object method = makeMethod(t,
flags,
0, // offset
0, // vm flags
parameterCount,
parameterFootprint,
flags,
0, // offset
arrayBody(t, pool, name - 1),
arrayBody(t, pool, spec - 1),
class_,
@ -1791,7 +1802,7 @@ hashMapInsert(Thread* t, object map, object key, object value,
PROTECT(t, value);
t->vm->weakReferences = makeWeakReference
(t, 0, 0, t->vm->weakReferences, 0);
(t, t->vm->weakReferences, 0, 0, 0);
jreferenceTarget(t, t->vm->weakReferences) = key;
key = t->vm->weakReferences;
}

View File

@ -91,8 +91,8 @@ make(Thread* t, object class_)
ACQUIRE(t, t->vm->referenceLock);
// jreferenceNext(t, r)
cast<object>(instance, 3 * BytesPerWord) = t->vm->weakReferences;
// jreferenceNext(t, instance)
cast<object>(instance, BytesPerWord) = t->vm->weakReferences;
t->vm->weakReferences = instance;
}

View File

@ -236,9 +236,10 @@ class MySystem: public System {
class Library: public System::Library {
public:
Library(System* s, void* p, System::Library* next):
Library(System* s, void* p, const char* name, System::Library* next):
s(s),
p(p),
name_(name),
next_(next)
{ }
@ -246,6 +247,10 @@ class MySystem: public System {
return dlsym(p, function);
}
virtual const char* name() {
return name_;
}
virtual System::Library* next() {
return next_;
}
@ -260,11 +265,14 @@ class MySystem: public System {
if (next_) {
next_->dispose();
}
s->free(name_);
s->free(this);
}
System* s;
void* p;
const char* name_;
System::Library* next_;
};
@ -359,7 +367,8 @@ class MySystem: public System {
const char* name,
System::Library* next)
{
unsigned size = strlen(name) + 7;
unsigned nameLength = strlen(name);
unsigned size = nameLength + 7;
char buffer[size];
snprintf(buffer, size, "lib%s.so", name);
@ -369,13 +378,19 @@ class MySystem: public System {
fprintf(stderr, "open %s as %p\n", buffer, p);
}
*lib = new (System::allocate(sizeof(Library))) Library(this, p, next);
char* n = static_cast<char*>(System::allocate(nameLength + 1));
memcpy(n, name, nameLength + 1);
*lib = new (System::allocate(sizeof(Library))) Library(this, p, n, next);
return 0;
} else {
return 1;
}
}
virtual void exit(int code) {
::exit(code);
}
virtual void abort() {
::abort();
}

View File

@ -49,6 +49,7 @@ class System: public Allocator {
public:
virtual ~Library() { }
virtual void* resolve(const char* function) = 0;
virtual const char* name() = 0;
virtual Library* next() = 0;
virtual void dispose() = 0;
};
@ -64,6 +65,7 @@ class System: public Allocator {
unsigned count, unsigned size,
unsigned returnType) = 0;
virtual Status load(Library**, const char* name, Library* next) = 0;
virtual void exit(int code) = 0;
virtual void abort() = 0;
virtual void dispose() = 0;

View File

@ -17,19 +17,26 @@
(object staticTable)
(object initializer))
(type field
(type accessibleObject java/lang/reflect/AccessibleObject
(extends jobject))
(type field java/lang/reflect/Field
(extends accessibleObject)
(uint8_t vmFlags)
(uint8_t code)
(uint16_t flags)
(uint16_t offset)
(uint8_t code)
(object name)
(object spec)
(object class))
(type method
(type method java/lang/reflect/Method
(extends accessibleObject)
(uint8_t vmFlags)
(uint8_t parameterCount)
(uint16_t parameterFootprint)
(uint16_t flags)
(uint16_t offset)
(uint16_t parameterCount)
(uint16_t parameterFootprint)
(object name)
(object spec)
(object class)
@ -223,9 +230,9 @@
(type jreference java/lang/ref/Reference
(extends jobject)
(void* next)
(void* target)
(void* queue)
(void* next)
(object jnext))
(type weakReference java/lang/ref/WeakReference