@@ -133,6 +133,9 @@ public final class ObjectKlass extends Klass {
133
133
@ CompilationFinal //
134
134
private volatile int initState = LOADED ;
135
135
136
+ @ CompilationFinal //
137
+ private EspressoException linkError ;
138
+
136
139
@ CompilationFinal volatile KlassVersion klassVersion ;
137
140
138
141
// instance and hidden fields declared in this class and in its super classes
@@ -156,12 +159,15 @@ public final class ObjectKlass extends Klass {
156
159
157
160
public static final int LOADED = 0 ;
158
161
public static final int LINKING = 1 ;
159
- public static final int PREPARED = 2 ;
160
- public static final int LINKED = 3 ;
162
+ public static final int VERIFYING = 2 ;
163
+ public static final int FAILED_LINK = 3 ;
164
+ public static final int VERIFIED = 4 ;
165
+ public static final int PREPARED = 5 ;
166
+ public static final int LINKED = 6 ;
167
+ public static final int INITIALIZING = 7 ;
161
168
// Can be erroneous only if initialization triggered !
162
- public static final int ERRONEOUS = 4 ;
163
- public static final int INITIALIZING = 5 ;
164
- public static final int INITIALIZED = 6 ;
169
+ public static final int ERRONEOUS = 8 ;
170
+ public static final int INITIALIZED = 9 ;
165
171
166
172
private final StaticObject definingClassLoader ;
167
173
@@ -378,7 +384,7 @@ boolean isInitializingOrInitializedImpl() {
378
384
* case, if the state is INITIALIZING we cannot really check the lock because an object
379
385
* might have been leaked to another thread by the clinit.
380
386
*/
381
- return initState >= ERRONEOUS ;
387
+ return initState >= INITIALIZING ;
382
388
}
383
389
384
390
boolean isInitializedImpl () {
@@ -418,6 +424,12 @@ private void actualInit() {
418
424
initState = INITIALIZING ;
419
425
getContext ().getLogger ().log (Level .FINEST , "Initializing: {0}" , this .getNameAsString ());
420
426
427
+ for (Field f : getInitialStaticFields ()) {
428
+ if (!f .isRemoved ()) {
429
+ initField (f );
430
+ }
431
+ }
432
+
421
433
var tls = getContext ().getLanguage ().getThreadLocalState ();
422
434
tls .blockContinuationSuspension ();
423
435
try {
@@ -477,11 +489,6 @@ private void prepare() {
477
489
try {
478
490
if (!isPrepared ()) {
479
491
checkLoadingConstraints ();
480
- for (Field f : getInitialStaticFields ()) {
481
- if (!f .isRemoved ()) {
482
- initField (f );
483
- }
484
- }
485
492
initState = PREPARED ;
486
493
if (getContext ().isMainThreadCreated ()) {
487
494
if (getContext ().shouldReportVMEvents ()) {
@@ -593,7 +600,7 @@ private void checkLoadingConstraints() {
593
600
@ Override
594
601
public void ensureLinked () {
595
602
if (!isLinked ()) {
596
- checkErroneousVerification ();
603
+ checkErroneousLink ();
597
604
if (CompilerDirectives .isCompilationConstant (this )) {
598
605
CompilerDirectives .transferToInterpreterAndInvalidate ();
599
606
}
@@ -607,20 +614,30 @@ private void doLink() {
607
614
try {
608
615
if (!isLinkingOrLinked ()) {
609
616
initState = LINKING ;
610
- if (getSuperKlass () != null ) {
611
- getSuperKlass ().ensureLinked ();
612
- }
613
- for (ObjectKlass interf : getSuperInterfaces ()) {
614
- interf .ensureLinked ();
617
+ try {
618
+ if (getSuperKlass () != null ) {
619
+ getSuperKlass ().ensureLinked ();
620
+ }
621
+ for (ObjectKlass interf : getSuperInterfaces ()) {
622
+ interf .ensureLinked ();
623
+ }
624
+ } catch (EspressoException e ) {
625
+ setErroneousLink (e );
626
+ throw e ;
615
627
}
616
- prepare ();
617
628
verify ();
629
+ try {
630
+ prepare ();
631
+ } catch (EspressoException e ) {
632
+ setErroneousLink (e );
633
+ throw e ;
634
+ }
618
635
initState = LINKED ;
619
636
}
620
637
} finally {
621
638
getInitLock ().unlock ();
622
639
}
623
- checkErroneousVerification ();
640
+ checkErroneousLink ();
624
641
}
625
642
626
643
void initializeImpl () {
@@ -632,7 +649,7 @@ void initializeImpl() {
632
649
633
650
@ HostCompilerDirectives .InliningCutoff
634
651
private void doInitialize () {
635
- checkErroneousVerification ();
652
+ checkErroneousLink ();
636
653
checkErroneousInitialization ();
637
654
if (CompilerDirectives .isCompilationConstant (this )) {
638
655
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -656,60 +673,45 @@ private void recursiveInitialize() {
656
673
657
674
// region Verification
658
675
659
- @ CompilationFinal //
660
- private volatile int verificationStatus = UNVERIFIED ;
661
-
662
- @ CompilationFinal //
663
- private EspressoException verificationError = null ;
664
-
665
- private static final int FAILED_VERIFICATION = -1 ;
666
- private static final int UNVERIFIED = 0 ;
667
- private static final int VERIFYING = 1 ;
668
- private static final int VERIFIED = 2 ;
669
-
670
- private void setVerificationStatus (int status ) {
671
- verificationStatus = status ;
672
- }
673
-
674
676
private boolean isVerifyingOrVerified () {
675
- return verificationStatus >= VERIFYING ;
677
+ return initState >= VERIFYING ;
676
678
}
677
679
678
680
boolean isVerified () {
679
- return verificationStatus >= VERIFIED ;
681
+ return initState >= VERIFIED ;
680
682
}
681
683
682
- private void checkErroneousVerification () {
683
- if (verificationStatus == FAILED_VERIFICATION ) {
684
- throw verificationError ;
684
+ private void checkErroneousLink () {
685
+ if (initState == FAILED_LINK ) {
686
+ throw linkError ;
685
687
}
686
688
}
687
689
688
- private void setErroneousVerification (EspressoException e ) {
689
- verificationStatus = FAILED_VERIFICATION ;
690
- verificationError = e ;
690
+ private void setErroneousLink (EspressoException e ) {
691
+ initState = FAILED_LINK ;
692
+ linkError = e ;
691
693
}
692
694
693
695
private void verify () {
694
696
if (!isVerified ()) {
695
- checkErroneousVerification ();
697
+ checkErroneousLink ();
696
698
getInitLock ().lock ();
697
699
try {
698
700
if (!isVerifyingOrVerified ()) {
699
701
CompilerDirectives .transferToInterpreterAndInvalidate ();
700
- setVerificationStatus ( VERIFYING ) ;
702
+ initState = VERIFYING ;
701
703
try {
702
704
verifyImpl ();
703
705
} catch (EspressoException e ) {
704
- setErroneousVerification (e );
706
+ setErroneousLink (e );
705
707
throw e ;
706
708
}
707
- setVerificationStatus ( VERIFIED ) ;
709
+ initState = VERIFIED ;
708
710
}
709
711
} finally {
710
712
getInitLock ().unlock ();
711
713
}
712
- checkErroneousVerification ();
714
+ checkErroneousLink ();
713
715
}
714
716
}
715
717
0 commit comments