mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 11:34:38 +02:00
8020224: LinkageError: attempted duplicate class definition when --loader-per-compiler=false
Reviewed-by: hannesw
This commit is contained in:
parent
cfbe70e223
commit
41c47ddf53
4 changed files with 73 additions and 1 deletions
|
@ -528,7 +528,7 @@ public final class Compiler {
|
|||
return this.env;
|
||||
}
|
||||
|
||||
private static String safeSourceName(final Source source) {
|
||||
private String safeSourceName(final Source source) {
|
||||
String baseName = new File(source.getName()).getName();
|
||||
|
||||
final int index = baseName.lastIndexOf(".js");
|
||||
|
@ -537,6 +537,9 @@ public final class Compiler {
|
|||
}
|
||||
|
||||
baseName = baseName.replace('.', '_').replace('-', '_');
|
||||
if (! env._loader_per_compile) {
|
||||
baseName = baseName + installer.getUniqueScriptId();
|
||||
}
|
||||
final String mangled = NameCodec.encode(baseName);
|
||||
|
||||
return mangled != null ? mangled : baseName;
|
||||
|
|
|
@ -62,4 +62,10 @@ public interface CodeInstaller<T> {
|
|||
* @param code bytecode to verify
|
||||
*/
|
||||
public void verify(final byte[] code);
|
||||
|
||||
/**
|
||||
* Get next unique script id
|
||||
* @return unique script id
|
||||
*/
|
||||
public long getUniqueScriptId();
|
||||
}
|
||||
|
|
|
@ -96,6 +96,11 @@ public final class Context {
|
|||
public void verify(final byte[] code) {
|
||||
context.verify(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUniqueScriptId() {
|
||||
return context.getUniqueScriptId();
|
||||
}
|
||||
}
|
||||
|
||||
/** Is Context global debug mode enabled ? */
|
||||
|
@ -197,6 +202,9 @@ public final class Context {
|
|||
/** Current error manager. */
|
||||
private final ErrorManager errors;
|
||||
|
||||
/** Unique id for script. Used only when --loader-per-compile=false */
|
||||
private long uniqueScriptId;
|
||||
|
||||
private static final ClassLoader myLoader = Context.class.getClassLoader();
|
||||
private static final StructureLoader sharedLoader;
|
||||
private static final AccessControlContext NO_PERMISSIONS_CONTEXT;
|
||||
|
@ -816,4 +824,8 @@ public final class Context {
|
|||
private ScriptObject newGlobalTrusted() {
|
||||
return new Global(this);
|
||||
}
|
||||
|
||||
private synchronized long getUniqueScriptId() {
|
||||
return uniqueScriptId++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,4 +145,55 @@ public class TrustedScriptEngineTest {
|
|||
|
||||
fail("Cannot find nashorn factory!");
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Test repeated evals with --loader-per-compile=false
|
||||
* We used to get "class redefinition error".
|
||||
*/
|
||||
public void noLoaderPerCompilerTest() {
|
||||
final ScriptEngineManager sm = new ScriptEngineManager();
|
||||
for (ScriptEngineFactory fac : sm.getEngineFactories()) {
|
||||
if (fac instanceof NashornScriptEngineFactory) {
|
||||
final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
|
||||
final String[] options = new String[] { "--loader-per-compile=false" };
|
||||
final ScriptEngine e = nfac.getScriptEngine(options);
|
||||
try {
|
||||
e.eval("2 + 3");
|
||||
e.eval("4 + 4");
|
||||
} catch (final ScriptException se) {
|
||||
se.printStackTrace();
|
||||
fail(se.getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Cannot find nashorn factory!");
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Test that we can use same script name in repeated evals with --loader-per-compile=false
|
||||
* We used to get "class redefinition error" as name was derived from script name.
|
||||
*/
|
||||
public void noLoaderPerCompilerWithSameNameTest() {
|
||||
final ScriptEngineManager sm = new ScriptEngineManager();
|
||||
for (ScriptEngineFactory fac : sm.getEngineFactories()) {
|
||||
if (fac instanceof NashornScriptEngineFactory) {
|
||||
final NashornScriptEngineFactory nfac = (NashornScriptEngineFactory)fac;
|
||||
final String[] options = new String[] { "--loader-per-compile=false" };
|
||||
final ScriptEngine e = nfac.getScriptEngine(options);
|
||||
e.put(ScriptEngine.FILENAME, "test.js");
|
||||
try {
|
||||
e.eval("2 + 3");
|
||||
e.eval("4 + 4");
|
||||
} catch (final ScriptException se) {
|
||||
se.printStackTrace();
|
||||
fail(se.getMessage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Cannot find nashorn factory!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue