diff --git a/classpath/TestExceptions.java b/classpath/TestExceptions.java new file mode 100644 index 0000000000..c37e685879 --- /dev/null +++ b/classpath/TestExceptions.java @@ -0,0 +1,19 @@ +public class TestExceptions { + + private static void evenMoreDangerous() { + throw new RuntimeException("chaos! panic! overwhelming anxiety!"); + } + + private static void moreDangerous() { + evenMoreDangerous(); + } + + private static void dangerous() { + moreDangerous(); + } + + public static void main(String[] args) { + dangerous(); + } + +} diff --git a/classpath/java/lang/Error.java b/classpath/java/lang/Error.java new file mode 100644 index 0000000000..dfce541509 --- /dev/null +++ b/classpath/java/lang/Error.java @@ -0,0 +1,19 @@ +package java.lang; + +public class Error extends Throwable { + public Error(String message, Throwable cause) { + super(message, cause); + } + + public Error(String message) { + this(message, null); + } + + public Error(Throwable cause) { + this(null, cause); + } + + public Error() { + this(null, null); + } +} diff --git a/classpath/java/lang/Exception.java b/classpath/java/lang/Exception.java new file mode 100644 index 0000000000..5b4f1d47b4 --- /dev/null +++ b/classpath/java/lang/Exception.java @@ -0,0 +1,19 @@ +package java.lang; + +public class Exception extends Throwable { + public Exception(String message, Throwable cause) { + super(message, cause); + } + + public Exception(String message) { + this(message, null); + } + + public Exception(Throwable cause) { + this(null, cause); + } + + public Exception() { + this(null, null); + } +} diff --git a/classpath/java/lang/RuntimeException.java b/classpath/java/lang/RuntimeException.java new file mode 100644 index 0000000000..e0930b8c62 --- /dev/null +++ b/classpath/java/lang/RuntimeException.java @@ -0,0 +1,19 @@ +package java.lang; + +public class RuntimeException extends Exception { + public RuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public RuntimeException(String message) { + this(message, null); + } + + public RuntimeException(Throwable cause) { + this(null, cause); + } + + public RuntimeException() { + this(null, null); + } +} diff --git a/classpath/java/lang/StackTraceElement.java b/classpath/java/lang/StackTraceElement.java new file mode 100644 index 0000000000..73bf1b38b0 --- /dev/null +++ b/classpath/java/lang/StackTraceElement.java @@ -0,0 +1,8 @@ +package java.lang; + +public class StackTraceElement { + private Object method; + private int ip; + + private StackTraceElement() { } +} diff --git a/classpath/java/lang/Throwable.java b/classpath/java/lang/Throwable.java index d4330f7bf4..8660e7e5b9 100644 --- a/classpath/java/lang/Throwable.java +++ b/classpath/java/lang/Throwable.java @@ -7,7 +7,7 @@ public class Throwable { public Throwable(String message, Throwable cause) { this.message = message; - this.trace = trace(1); + this.trace = trace(0); this.cause = cause; } diff --git a/makefile b/makefile index 97ca7c1b11..63603eae5c 100644 --- a/makefile +++ b/makefile @@ -36,6 +36,7 @@ stress-cflags = -DDEBUG_MEMORY -DDEBUG_MEMORY_MAJOR cpp-objects = $(foreach x,$(1),$(patsubst $(2)/%.cpp,$(bld)/%.o,$(x))) asm-objects = $(foreach x,$(1),$(patsubst $(2)/%.S,$(bld)/%.o,$(x))) +java-classes = $(foreach x,$(1),$(patsubst $(2)/%.java,$(bld)/%.class,$(x))) stdcpp-sources = $(src)/stdc++.cpp stdcpp-objects = $(call cpp-objects,$(stdcpp-sources),$(src)) @@ -122,10 +123,14 @@ fast-objects = \ fast-executable = $(bld)/fast-vm fast-cflags = $(fast) $(cflags) +classpath-sources = $(shell find %(classpath)/java -name '*.java') +classpath-classes = $(call java-classes,$(classpath-sources),$(classpath)) + input = $(bld)/classes/TestExceptions.class -# input-depends = \ -# $(bld)/classes/java/lang/System.class \ -# $(jni-library) +input-depends = \ + $(bld)/classes/java/lang/System.class \ + $(bld)/classes/java/lang/Throwable.class \ + $(jni-library) gen-run-arg = $(shell echo $(1) | sed -e 's:$(bld)/classes/\(.*\)\.class:\1:') args = -cp $(bld)/classes -hs 67108864 $(call gen-run-arg,$(input)) diff --git a/src/vm.cpp b/src/vm.cpp index 39ef725e96..d27680a068 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -2532,7 +2532,7 @@ run(Thread* t) if (UNLIKELY(exception)) goto throw_; loop: - //fprintf(stderr, "ip: %d; instruction: 0x%x\n", ip, codeBody(t, code, ip)); +// fprintf(stderr, "ip: %d; instruction: 0x%x\n", ip, codeBody(t, code, ip)); switch (codeBody(t, code, ip++)) { case aaload: { @@ -3713,8 +3713,7 @@ run(Thread* t) } goto loop; case putfield: { - object instance = pop(t); - if (LIKELY(instance)) { + if (LIKELY(stack[sp - 2])) { uint8_t index1 = codeBody(t, code, ip++); uint8_t index2 = codeBody(t, code, ip++); uint16_t index = (index1 << 8) | index2; @@ -3723,6 +3722,7 @@ run(Thread* t) if (UNLIKELY(exception)) goto throw_; object value = pop(t); + object instance = pop(t); setField(t, instance, field, value); } else { exception = makeNullPointerException(t);