Skip to content

Commit 6a14dba

Browse files
Add EnableAdvancedRedefinition option
`EnableAdvancedRedefinition` controls whether things like method or field addition/removal and class hierarchy changes are enabled. It controls the access to such features both for JDWP and java agents.
1 parent 4f61e16 commit 6a14dba

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/EspressoOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,12 @@ public enum MemoryAccessOption {
763763
usageSyntax = "allow|warn|debug|deny") //
764764
public static final OptionKey<MemoryAccessOption> SunMiscUnsafeMemoryAccess = new OptionKey<>(MemoryAccessOption.defaultValue);
765765

766+
@Option(help = "Enable advanced class redefinition.", //
767+
category = OptionCategory.EXPERT, //
768+
stability = OptionStability.EXPERIMENTAL, //
769+
usageSyntax = "false|true") //
770+
public static final OptionKey<Boolean> EnableAdvancedRedefinition = new OptionKey<>(false);
771+
766772
/**
767773
* Property used to force liveness analysis to also be applied by the interpreter. For testing
768774
* purpose only. Use a host property rather than an option. An option would slow interpreter

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/redefinition/ClassRedefinition.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,15 @@ public List<ChangePacket> detectClassChanges(HotSwapClassInfo[] classInfos, bool
258258
}
259259

260260
@TruffleBoundary
261-
public void redefineClasses(RedefineInfo[] redefineInfos, boolean applyTransformers) {
262-
redefineClasses(Arrays.asList(redefineInfos), true, applyTransformers);
261+
public int redefineClasses(RedefineInfo[] redefineInfos, boolean applyTransformers) {
262+
return redefineClasses(Arrays.asList(redefineInfos), applyTransformers);
263263
}
264264

265-
public synchronized int redefineClasses(List<RedefineInfo> redefineInfos, boolean jvmtiRestrictions, boolean applyTransformers) {
265+
public int redefineClasses(List<RedefineInfo> redefineInfos, boolean applyTransformers) {
266+
return redefineClasses(redefineInfos, !context.advancedRedefinitionEnabled(), applyTransformers);
267+
}
268+
269+
private synchronized int redefineClasses(List<RedefineInfo> redefineInfos, boolean jvmtiRestrictions, boolean applyTransformers) {
266270
List<RedefineInfo> resultingInfos = applyTransformers ? getTransformedInfos(redefineInfos) : redefineInfos;
267271

268272
// make sure the modules of redefined classes can read injected agent classes
@@ -465,7 +469,7 @@ private static ClassChange detectClassChanges(ParserKlass newParserKlass, Object
465469
throw meta.throwExceptionWithMessage(meta.java_lang_UnsupportedOperationException, "attempted to redefine record attribute");
466470
}
467471
if (attrChanged(oldKlass.getAttribute(PermittedSubclassesAttribute.NAME), newParserKlass.getAttribute(PermittedSubclassesAttribute.NAME), oldConstantPool, newConstantPool)) {
468-
throw meta.throwExceptionWithMessage(meta.java_lang_UnsupportedOperationException, "attempted to redefine record attribute");
472+
throw meta.throwExceptionWithMessage(meta.java_lang_UnsupportedOperationException, "attempted to redefine permitted subclasses attribute");
469473
}
470474
}
471475

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/EspressoContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ public JavaVersion getJavaVersion() {
896896
}
897897

898898
public boolean advancedRedefinitionEnabled() {
899-
return espressoEnv.JDWPOptions != null;
899+
return espressoEnv.AdvancedRedefinition;
900900
}
901901

902902
public TypeSymbols getTypes() {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/EspressoEnv.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public final class EspressoEnv {
105105
private final PolyglotTypeMappings polyglotTypeMappings;
106106
private final boolean enableGenericTypeHints;
107107
private final HashMap<String, EspressoForeignProxyGenerator.GeneratedProxyBytes> proxyCache;
108+
public final boolean AdvancedRedefinition;
108109

109110
// Debug option
110111
public final com.oracle.truffle.espresso.jdwp.api.JDWPOptions JDWPOptions;
@@ -168,6 +169,7 @@ public EspressoEnv(EspressoContext context, TruffleLanguage.Env env) {
168169
this.enableGenericTypeHints = env.getOptions().get(EspressoOptions.EnableGenericTypeHints);
169170
this.proxyCache = polyglotTypeMappings.hasMappings() ? new HashMap<>() : null;
170171
this.UseBindingsLoader = env.getOptions().get(EspressoOptions.UseBindingsLoader);
172+
this.AdvancedRedefinition = env.getOptions().get(EspressoOptions.EnableAdvancedRedefinition);
171173

172174
EspressoOptions.JImageMode requestedJImageMode = env.getOptions().get(EspressoOptions.JImage);
173175
if (!NativeAccessAllowed && requestedJImageMode == EspressoOptions.JImageMode.NATIVE) {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/runtime/JDWPContextImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ public ModuleRef[] getAllModulesRefs() {
828828
}
829829

830830
public synchronized int redefineClasses(List<RedefineInfo> redefineInfos) {
831-
return context.getClassRedefinition().redefineClasses(redefineInfos, false, true);
831+
return context.getClassRedefinition().redefineClasses(redefineInfos, true);
832832
}
833833

834834
@Override

0 commit comments

Comments
 (0)