2727import com .oracle .truffle .espresso .descriptors .Symbol ;
2828import com .oracle .truffle .espresso .impl .ContextAccessImpl ;
2929import com .oracle .truffle .espresso .impl .ObjectKlass ;
30+ import com .oracle .truffle .espresso .runtime .EspressoContext ;
3031import com .oracle .truffle .espresso .runtime .StaticObject ;
3132import 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 */
3637public 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