Skip to content

Commit 017d941

Browse files
[GR-39184] Avoid recursive inlining in allocation path.
PullRequest: graal/11985
2 parents 6b71dc1 + e8c9cbd commit 017d941

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Klass.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,13 +982,18 @@ public void safeInitialize() {
982982
StaticObject cause = e.getGuestException();
983983
Meta meta = getMeta();
984984
if (!InterpreterToVM.instanceOf(cause, meta.java_lang_Error)) {
985-
throw meta.throwExceptionWithCause(meta.java_lang_ExceptionInInitializerError, cause);
985+
throw throwExceptionInInitializerError(meta, cause);
986986
} else {
987987
throw e;
988988
}
989989
}
990990
}
991991

992+
@TruffleBoundary
993+
private static EspressoException throwExceptionInInitializerError(Meta meta, StaticObject cause) {
994+
throw meta.throwExceptionWithCause(meta.java_lang_ExceptionInInitializerError, cause);
995+
}
996+
992997
public final Klass getSupertype() {
993998
if (isPrimitive()) {
994999
return null;

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/ObjectKlass.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,16 @@ boolean isErroneous() {
364364

365365
private void checkErroneousInitialization() {
366366
if (isErroneous()) {
367-
Meta meta = getMeta();
368-
throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, EspressoError.cat("Erroneous class: ", getName()));
367+
throw throwNoClassDefFoundError();
369368
}
370369
}
371370

371+
@TruffleBoundary
372+
private EspressoException throwNoClassDefFoundError() {
373+
Meta meta = getMeta();
374+
throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, "Erroneous class: " + getName());
375+
}
376+
372377
@ExplodeLoop
373378
private void actualInit() {
374379
checkErroneousInitialization();

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/meta/ExceptionDispatch.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
import com.oracle.truffle.espresso.descriptors.Symbol;
2828
import com.oracle.truffle.espresso.impl.ContextAccessImpl;
2929
import com.oracle.truffle.espresso.impl.ObjectKlass;
30+
import com.oracle.truffle.espresso.runtime.EspressoContext;
3031
import com.oracle.truffle.espresso.runtime.StaticObject;
3132
import com.oracle.truffle.espresso.vm.InterpreterToVM;
3233

3334
/**
34-
* Allows fast-path runtime guest exception creation.
35+
* Allows fast-path creation of well-known guest runtime exceptions .
3536
*/
3637
public final class ExceptionDispatch extends ContextAccessImpl {
3738
private final Meta meta;
@@ -57,8 +58,7 @@ StaticObject initEx(ObjectKlass klass, StaticObject message, StaticObject cause)
5758
}
5859

5960
private StaticObject fastPath(ObjectKlass klass, StaticObject message, StaticObject cause) {
60-
StaticObject ex = klass.allocateInstance(getContext());
61-
61+
StaticObject ex = allocateException(klass);
6262
// TODO: Remove this when truffle exceptions are reworked.
6363
InterpreterToVM.fillInStackTrace(ex, false, meta);
6464

@@ -71,12 +71,20 @@ private StaticObject fastPath(ObjectKlass klass, StaticObject message, StaticObj
7171
return ex;
7272
}
7373

74+
private StaticObject allocateException(ObjectKlass klass) {
75+
EspressoContext ctx = getContext();
76+
// avoid PE recursion in the checks in klass.allocateInstance
77+
// the exception types allocated here should be well-known and well-behaved
78+
assert !klass.isAbstract() && !klass.isInterface();
79+
return ctx.getAllocator().createNew(klass);
80+
}
81+
7482
private StaticObject slowPath(ObjectKlass klass, StaticObject message, StaticObject cause) {
7583
assert meta.java_lang_Throwable.isAssignableFrom(klass);
7684
StaticObject ex;
7785
// if klass was a compilation constant, the constantness of the klass field in ex should
7886
// propagate even through the boundary.
79-
ex = klass.allocateInstance(getContext());
87+
ex = allocateException(klass);
8088
slowInitEx(ex, klass, message, cause);
8189
return ex;
8290
}

0 commit comments

Comments
 (0)