@@ -133,7 +133,7 @@ public final class ObjectKlass extends Klass {
133
133
private volatile int initState = LOADED ;
134
134
135
135
@ CompilationFinal //
136
- private EspressoException linkError ;
136
+ private StaticObject initializationError ;
137
137
138
138
@ CompilationFinal volatile KlassVersion klassVersion ;
139
139
@@ -159,14 +159,13 @@ public final class ObjectKlass extends Klass {
159
159
public static final int LOADED = 0 ;
160
160
public static final int LINKING = 1 ;
161
161
public static final int VERIFYING = 2 ;
162
- public static final int FAILED_LINK = 3 ;
163
- public static final int VERIFIED = 4 ;
164
- public static final int PREPARED = 5 ;
165
- public static final int LINKED = 6 ;
166
- public static final int INITIALIZING = 7 ;
162
+ public static final int VERIFIED = 3 ;
163
+ public static final int PREPARED = 4 ;
164
+ public static final int LINKED = 5 ;
165
+ public static final int INITIALIZING = 6 ;
167
166
// Can be erroneous only if initialization triggered !
168
- public static final int ERRONEOUS = 8 ;
169
- public static final int INITIALIZED = 9 ;
167
+ public static final int ERRONEOUS = 7 ;
168
+ public static final int INITIALIZED = 8 ;
170
169
171
170
private final StaticObject definingClassLoader ;
172
171
@@ -361,8 +360,10 @@ boolean isInitializedImpl() {
361
360
return initState >= INITIALIZED ;
362
361
}
363
362
364
- private void setErroneousInitialization () {
363
+ private void setErroneousInitialization (StaticObject exception ) {
364
+ assert exception != null ;
365
365
initState = ERRONEOUS ;
366
+ initializationError = exception ;
366
367
}
367
368
368
369
boolean isErroneous () {
@@ -377,8 +378,13 @@ private void checkErroneousInitialization() {
377
378
378
379
@ TruffleBoundary
379
380
private EspressoException throwNoClassDefFoundError () {
381
+ assert isErroneous ();
380
382
Meta meta = getMeta ();
381
- throw meta .throwExceptionWithMessage (meta .java_lang_NoClassDefFoundError , "Erroneous class: " + getName ());
383
+ if (StaticObject .isNull (initializationError )) {
384
+ throw meta .throwExceptionWithMessage (meta .java_lang_NoClassDefFoundError , "Could not initialize class: " + getExternalName ());
385
+ } else {
386
+ throw meta .throwException (meta .java_lang_NoClassDefFoundError , "Could not initialize class: " + getExternalName (), initializationError );
387
+ }
382
388
}
383
389
384
390
@ TruffleBoundary
@@ -426,15 +432,15 @@ private void actualInit() {
426
432
clinit .invokeDirectStatic ();
427
433
}
428
434
} catch (EspressoException e ) {
429
- setErroneousInitialization ();
435
+ setErroneousInitialization (e . getGuestException () );
430
436
throw initializationFailed (e );
431
437
} catch (AbstractTruffleException e ) {
432
- setErroneousInitialization ();
438
+ setErroneousInitialization (StaticObject . NULL );
433
439
throw e ;
434
440
} catch (Throwable e ) {
435
441
getContext ().getLogger ().log (Level .WARNING , "Host exception during class initialization: {0}" , this .getNameAsString ());
436
442
e .printStackTrace ();
437
- setErroneousInitialization ();
443
+ setErroneousInitialization (StaticObject . NULL );
438
444
throw e ;
439
445
}
440
446
checkErroneousInitialization ();
@@ -566,7 +572,6 @@ private void checkLoadingConstraints() {
566
572
@ Override
567
573
public void ensureLinked () {
568
574
if (!isLinked ()) {
569
- checkErroneousLink ();
570
575
if (CompilerDirectives .isCompilationConstant (this )) {
571
576
CompilerDirectives .transferToInterpreterAndInvalidate ();
572
577
}
@@ -579,6 +584,7 @@ private void doLink() {
579
584
getInitLock ().lock ();
580
585
try {
581
586
if (!isLinkingOrLinked ()) {
587
+ int initialState = initState ;
582
588
initState = LINKING ;
583
589
try {
584
590
if (getSuperKlass () != null ) {
@@ -587,23 +593,17 @@ private void doLink() {
587
593
for (ObjectKlass interf : getSuperInterfaces ()) {
588
594
interf .ensureLinked ();
589
595
}
590
- } catch (EspressoException e ) {
591
- setErroneousLink (e );
592
- throw e ;
593
- }
594
- verify ();
595
- try {
596
+ verify ();
596
597
prepare ();
597
- } catch (EspressoException e ) {
598
- setErroneousLink (e );
599
- throw e ;
598
+ initState = LINKED ;
599
+ } catch (Throwable t ) {
600
+ initState = initialState ;
601
+ throw t ;
600
602
}
601
- initState = LINKED ;
602
603
}
603
604
} finally {
604
605
getInitLock ().unlock ();
605
606
}
606
- checkErroneousLink ();
607
607
}
608
608
609
609
void initializeImpl () {
@@ -615,7 +615,6 @@ void initializeImpl() {
615
615
616
616
@ HostCompilerDirectives .InliningCutoff
617
617
private void doInitialize () {
618
- checkErroneousLink ();
619
618
checkErroneousInitialization ();
620
619
if (CompilerDirectives .isCompilationConstant (this )) {
621
620
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -647,37 +646,25 @@ boolean isVerified() {
647
646
return initState >= VERIFIED ;
648
647
}
649
648
650
- private void checkErroneousLink () {
651
- if (initState == FAILED_LINK ) {
652
- throw linkError ;
653
- }
654
- }
655
-
656
- private void setErroneousLink (EspressoException e ) {
657
- initState = FAILED_LINK ;
658
- linkError = e ;
659
- }
660
-
661
649
private void verify () {
662
650
if (!isVerified ()) {
663
- checkErroneousLink ();
664
651
getInitLock ().lock ();
665
652
try {
666
653
if (!isVerifyingOrVerified ()) {
667
654
CompilerDirectives .transferToInterpreterAndInvalidate ();
655
+ int initialState = initState ;
668
656
initState = VERIFYING ;
669
657
try {
670
658
verifyImpl ();
671
- } catch (EspressoException e ) {
672
- setErroneousLink (e );
673
- throw e ;
659
+ initState = VERIFIED ;
660
+ } catch (Throwable t ) {
661
+ initState = initialState ;
662
+ throw t ;
674
663
}
675
- initState = VERIFIED ;
676
664
}
677
665
} finally {
678
666
getInitLock ().unlock ();
679
667
}
680
- checkErroneousLink ();
681
668
}
682
669
}
683
670
0 commit comments