Skip to content

Commit 8e380fa

Browse files
committed
Revise the initialization flow of interface as per specs
As per Java Language and JVM Specs, the initialization is changed to initialize Java interface's super interfaces if applicable with default method. Fixes: #24153
1 parent ae0eb28 commit 8e380fa

1 file changed

Lines changed: 25 additions & 26 deletions

File tree

runtime/vm/ClassInitialization.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -721,35 +721,34 @@ classInitStateMachine(J9VMThread *currentThread, J9Class *clazz, J9ClassInitStat
721721
}
722722
superITable = (J9ITable*)superclazz->iTable;
723723
}
724-
/* Do not initialize the superinterfaces of interfaces */
725-
if (!J9_ARE_ANY_BITS_SET(clazz->romClass->modifiers, J9AccInterface)) {
726-
/* Initialize super-interfaces with non-static, non-abstract methods */
727-
Trc_VM_classInitStateMachine_initSuperInterfacesWithNonStaticNonAbstractMethods(currentThread, clazz);
728-
/* Don't traverse all iTables - indirect super-interfaces are initialized with the superclass */
729-
firstITable = (J9ITable*)clazz->iTable;
730-
iTable = firstITable;
731-
while (iTable != superITable) {
732-
J9Class *interfaceClazz = iTable->interfaceClass;
733-
if (J9_ARE_ANY_BITS_SET(interfaceClazz->romClass->extraModifiers, J9AccClassHasNonStaticNonAbstractMethods)) {
734-
PUSH_OBJECT_IN_SPECIAL_FRAME(currentThread, initializationLock);
735-
classInitStateMachine(currentThread, interfaceClazz, J9_CLASS_INIT_INITIALIZED);
736-
initializationLock = POP_OBJECT_IN_SPECIAL_FRAME(currentThread);
737-
clazz = VM_VMHelpers::currentClass(clazz);
738-
if (VM_VMHelpers::exceptionPending(currentThread)) {
739-
goto initFailed;
740-
}
741-
/* Ensure that we are still traversing a valid iTable chain */
742-
if (firstITable != (J9ITable*)clazz->iTable) {
743-
iTable = (J9ITable*)clazz->iTable;
744-
if (NULL != superclazz) {
745-
superclazz = VM_VMHelpers::getSuperclass(clazz);
746-
superITable = (J9ITable*)superclazz->iTable;
747-
}
748-
continue;
724+
725+
/* Initialize super-interfaces with non-static, non-abstract methods */
726+
Trc_VM_classInitStateMachine_initSuperInterfacesWithNonStaticNonAbstractMethods(currentThread, clazz);
727+
/* Don't traverse all iTables - indirect super-interfaces are initialized with the superclass */
728+
firstITable = (J9ITable*)clazz->iTable;
729+
iTable = firstITable;
730+
while (iTable != superITable) {
731+
J9Class *interfaceClazz = iTable->interfaceClass;
732+
733+
if (J9_ARE_ANY_BITS_SET(interfaceClazz->romClass->extraModifiers, J9AccClassHasNonStaticNonAbstractMethods)) {
734+
PUSH_OBJECT_IN_SPECIAL_FRAME(currentThread, initializationLock);
735+
classInitStateMachine(currentThread, interfaceClazz, J9_CLASS_INIT_INITIALIZED);
736+
initializationLock = POP_OBJECT_IN_SPECIAL_FRAME(currentThread);
737+
clazz = VM_VMHelpers::currentClass(clazz);
738+
if (VM_VMHelpers::exceptionPending(currentThread)) {
739+
goto initFailed;
740+
}
741+
/* Ensure that we are still traversing a valid iTable chain */
742+
if (firstITable != (J9ITable*)clazz->iTable) {
743+
iTable = (J9ITable*)clazz->iTable;
744+
if (NULL != superclazz) {
745+
superclazz = VM_VMHelpers::getSuperclass(clazz);
746+
superITable = (J9ITable*)superclazz->iTable;
749747
}
748+
continue;
750749
}
751-
iTable = iTable->next;
752750
}
751+
iTable = iTable->next;
753752
}
754753

755754
#if defined(J9VM_OPT_VALHALLA_FLATTENABLE_VALUE_TYPES)

0 commit comments

Comments
 (0)