Skip to content

Commit 3b10026

Browse files
committed
Prevent repeated initialization of "net" library.
1 parent 69794db commit 3b10026

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/NativeLibrarySupport.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private boolean loadLibrary0(File file, boolean asBuiltin) {
141141
return addLibrary(asBuiltin, canonical, true);
142142
}
143143

144-
private boolean addLibrary(boolean asBuiltin, String canonical, boolean loadAndInitialize) {
144+
private boolean addLibrary(boolean asBuiltin, String canonical, boolean initialize) {
145145
lock.lock();
146146
try {
147147
NativeLibrary lib = null;
@@ -171,19 +171,22 @@ private boolean addLibrary(boolean asBuiltin, String canonical, boolean loadAndI
171171
lib = PlatformNativeLibrarySupport.singleton().createLibrary(canonical, asBuiltin);
172172
created = true;
173173
}
174-
if (loadAndInitialize) {
175-
currentLoadContext.push(lib);
176-
try {
177-
if (!lib.load()) {
178-
return false;
179-
}
180-
if (libraryInitializer != null) {
181-
libraryInitializer.initialize(lib);
182-
}
183-
} finally {
184-
NativeLibrary top = currentLoadContext.pop();
185-
assert top == lib;
174+
currentLoadContext.push(lib);
175+
try {
176+
if (!lib.load()) {
177+
return false;
178+
}
179+
/*
180+
* Initialization of a library must be skipped if it can be initialized at most once
181+
* per process and another isolate has already initialized it. However, the library
182+
* must be (marked as) loaded above so it cannot be loaded and initialized later.
183+
*/
184+
if (initialize && libraryInitializer != null) {
185+
libraryInitializer.initialize(lib);
186186
}
187+
} finally {
188+
NativeLibrary top = currentLoadContext.pop();
189+
assert top == lib;
187190
}
188191
if (created) {
189192
knownLibraries.add(lib);
@@ -210,6 +213,7 @@ public PointerBase findSymbol(String name) {
210213
}
211214

212215
public void registerInitializedBuiltinLibrary(String name) {
213-
addLibrary(true, name, false);
216+
boolean success = addLibrary(true, name, false);
217+
assert success;
214218
}
215219
}

0 commit comments

Comments
 (0)