# HG changeset patch # User Doug Simon # Date 1354798892 -3600 # Node ID ae1f369117438de8ba6567938a1c8618beec2ac6 # Parent a818db37b7be862b2ffc3791cdaf7508177f26ac created shared, cached exceptions with empty stack traces for the implementation of the -G:+OmitHotExceptionStacktrace option. This also avoids the issue of having an object embedded in compiled code without an external strong reference to the same object (objects in compiled code are weak references in HotSpot) diff -r a818db37b7be -r ae1f36911743 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Dec 05 13:57:00 2012 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Dec 06 14:01:32 2012 +0100 @@ -775,7 +775,7 @@ lastInstr = falseSucc; if (GraalOptions.OmitHotExceptionStacktrace) { - ValueNode exception = ConstantNode.forObject(new NullPointerException(), runtime, currentGraph); + ValueNode exception = ConstantNode.forObject(cachedNullPointerException, runtime, currentGraph); trueSucc.setNext(handleException(exception, bci())); } else { RuntimeCallNode call = currentGraph.add(new RuntimeCallNode(CREATE_NULL_POINTER_EXCEPTION)); @@ -785,6 +785,14 @@ } } + private static final ArrayIndexOutOfBoundsException cachedArrayIndexOutOfBoundsException = new ArrayIndexOutOfBoundsException(); + private static final NullPointerException cachedNullPointerException = new NullPointerException(); + static { + cachedArrayIndexOutOfBoundsException.setStackTrace(new StackTraceElement[0]); + cachedNullPointerException.setStackTrace(new StackTraceElement[0]); + } + + private void emitBoundsCheck(ValueNode index, ValueNode length) { BlockPlaceholderNode trueSucc = currentGraph.add(new BlockPlaceholderNode()); BlockPlaceholderNode falseSucc = currentGraph.add(new BlockPlaceholderNode()); @@ -794,7 +802,7 @@ lastInstr = trueSucc; if (GraalOptions.OmitHotExceptionStacktrace) { - ValueNode exception = ConstantNode.forObject(new ArrayIndexOutOfBoundsException(), runtime, currentGraph); + ValueNode exception = ConstantNode.forObject(cachedArrayIndexOutOfBoundsException, runtime, currentGraph); falseSucc.setNext(handleException(exception, bci())); } else { RuntimeCallNode call = currentGraph.add(new RuntimeCallNode(CREATE_OUT_OF_BOUNDS_EXCEPTION, index));