Skip to content

[GR-64633] Espresso: Integrate TRegex for JDK25 #11701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ FieldBuilder generateFactoryConstructor(FieldBuilder factoryBuilder, String subs
LanguageFilter filter,
byte flags,
InlinedMethodPredicate guard,
Constructor<? extends JavaSubstitution> constructor);
Supplier<? extends JavaSubstitution> factory);
}
*/
SubstitutorHelper h = (SubstitutorHelper) helper;
Expand All @@ -663,7 +663,7 @@ FieldBuilder generateFactoryConstructor(FieldBuilder factoryBuilder, String subs
declaration.addContent(h.languageFilter, '.', INSTANCE, ',').addLine();
declaration.addContent("(byte) ", h.flags, ',').addLine();
declaration.addContent(h.guardValue != null ? (h.guardValue + "." + INSTANCE) : "null", ',').addLine();
declaration.addContent(generateLookupConstructor(substitutorName, substitutorType)).addLine();
declaration.addContent(substitutorName + "::new").addLine();
declaration.lowerIndent().addContent(")");
factoryBuilder.withDeclaration(declaration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public final class EspressoLanguage extends TruffleLanguage<EspressoContext> imp
@CompilationFinal private boolean internalJvmciEnabled;
@CompilationFinal private boolean useEspressoLibs;
@CompilationFinal private boolean continuum;
@CompilationFinal private boolean useTRegex;
// endregion Options

// region Allocation
Expand Down Expand Up @@ -246,6 +247,11 @@ private void initializeOptions(final TruffleLanguage.Env env) {
internalJvmciEnabled = env.getOptions().get(EspressoOptions.EnableJVMCI);
continuum = env.getOptions().get(EspressoOptions.Continuum);

useTRegex = env.getOptions().get(EspressoOptions.UseTRegex);
if (useTRegex && !env.getInternalLanguages().containsKey("regex")) {
throw EspressoError.fatal("UseTRegex is set to true but the 'regex' language is not available.");
}

EspressoOptions.GuestFieldOffsetStrategyEnum strategy = env.getOptions().get(EspressoOptions.GuestFieldOffsetStrategy);
guestFieldOffsetStrategy = switch (strategy) {
case safety -> new SafetyGuestFieldOffsetStrategy();
Expand Down Expand Up @@ -343,6 +349,7 @@ protected boolean areOptionsCompatible(OptionValues oldOptions, OptionValues new
isOptionCompatible(newOptions, oldOptions, EspressoOptions.WhiteBoxAPI) &&
isOptionCompatible(newOptions, oldOptions, EspressoOptions.EnableJVMCI) &&
isOptionCompatible(newOptions, oldOptions, EspressoOptions.Continuum) &&
isOptionCompatible(newOptions, oldOptions, EspressoOptions.UseTRegex) &&
isOptionCompatible(newOptions, oldOptions, EspressoOptions.GuestFieldOffsetStrategy) &&
isOptionCompatible(newOptions, oldOptions, EspressoOptions.UseEspressoLibs);
}
Expand Down Expand Up @@ -582,6 +589,10 @@ public boolean isJVMCIEnabled() {
return internalJvmciEnabled;
}

public boolean useTRegex() {
return useTRegex;
}

public boolean useEspressoLibs() {
return useEspressoLibs;
}
Expand Down Expand Up @@ -619,6 +630,9 @@ public void tryInitializeJavaVersion(JavaVersion version) {
if (!getGuestFieldOffsetStrategy().isAllowed(version)) {
throw EspressoError.fatal("This guest field offset strategy (" + getGuestFieldOffsetStrategy().name() + ") is not allowed with this Java version (" + version + ")");
}
if (useTRegex && !version.java21OrLater()) {
throw EspressoError.fatal("UseTRegex is not available for context running Java version < 21.");
}
this.javaVersion = ref = version;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ public static class Names {
public static final Symbol<Name> referent = SYMBOLS.putName("referent");
// java.util.regex
public static final Symbol<Name> parentPattern = SYMBOLS.putName("parentPattern");
public static final Symbol<Name> text = SYMBOLS.putName("text");
public static final Symbol<Name> pattern = SYMBOLS.putName("pattern");
public static final Symbol<Name> flags0 = SYMBOLS.putName("flags0");
public static final Symbol<Name> compiled = SYMBOLS.putName("compiled");
Expand Down Expand Up @@ -1005,9 +1006,11 @@ public static class Names {
public static final Symbol<Name> HIDDEN_TREGEX_MATCH = SYMBOLS.putName("0HIDDEN_TREGEX_MATCH");
public static final Symbol<Name> HIDDEN_TREGEX_FULLMATCH = SYMBOLS.putName("0HIDDEN_TREGEX_FULLMATCH");
public static final Symbol<Name> HIDDEN_TREGEX_SEARCH = SYMBOLS.putName("0HIDDEN_TREGEX_SEARCH");
public static final Symbol<Name> HIDDEN_TREGEX_UNSUPPORTED = SYMBOLS.putName("0HIDDEN_TREGEX_UNSUPPORTED");
public static final Symbol<Name> HIDDEN_TREGEX_STATUS = SYMBOLS.putName("0HIDDEN_TREGEX_STATUS");
// Matcher
public static final Symbol<Name> HIDDEN_TREGEX_TSTRING = SYMBOLS.putName("0HIDDEN_TREGEX_TSTRING");
public static final Symbol<Name> HIDDEN_TREGEX_TEXT_SYNC = SYMBOLS.putName("0HIDDEN_TREGEX_TEXT_SYNC");
public static final Symbol<Name> HIDDEN_TREGEX_PATTERN_SYNC = SYMBOLS.putName("0HIDDEN_TREGEX_PATTERN_SYNC");
public static final Symbol<Name> HIDDEN_TREGEX_OLD_LAST_BACKUP = SYMBOLS.putName("0HIDDEN_TREGEX_OLD_LAST_BACKUP");
public static final Symbol<Name> HIDDEN_TREGEX_MOD_COUNT_BACKUP = SYMBOLS.putName("0HIDDEN_TREGEX_MOD_COUNT_BACKUP");
public static final Symbol<Name> HIDDEN_TREGEX_TRANSPARENT_BOUNDS_BACKUP = SYMBOLS.putName("0HIDDEN_TREGEX_TRANSPARENT_BOUNDS_BACKUP");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,21 +240,23 @@ private static class HiddenField {
new HiddenField(Names.HIDDEN_MODULE_ENTRY)
}),
entry(Types.java_util_regex_Pattern, new HiddenField[]{
new HiddenField(Names.HIDDEN_TREGEX_MATCH),
new HiddenField(Names.HIDDEN_TREGEX_FULLMATCH),
new HiddenField(Names.HIDDEN_TREGEX_SEARCH),
new HiddenField(Names.HIDDEN_TREGEX_UNSUPPORTED)
new HiddenField(Names.HIDDEN_TREGEX_MATCH, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_FULLMATCH, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_SEARCH, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_STATUS, Types._int, EspressoLanguage::useTRegex, ACC_VOLATILE)
}),
entry(Types.java_util_regex_Matcher, new HiddenField[]{
new HiddenField(Names.HIDDEN_TREGEX_TSTRING),
new HiddenField(Names.HIDDEN_TREGEX_OLD_LAST_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_MOD_COUNT_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_TRANSPARENT_BOUNDS_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_ANCHORING_BOUNDS_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_FROM_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_TO_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_SEARCH_FROM_BACKUP),
new HiddenField(Names.HIDDEN_TREGEX_MATCHING_MODE_BACKUP)
new HiddenField(Names.HIDDEN_TREGEX_TSTRING, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_TEXT_SYNC, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_PATTERN_SYNC, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_OLD_LAST_BACKUP, Types._int, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_MOD_COUNT_BACKUP, Types._int, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_TRANSPARENT_BOUNDS_BACKUP, Types._boolean, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_ANCHORING_BOUNDS_BACKUP, Types._boolean, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_FROM_BACKUP, Types._int, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_TO_BACKUP, Types._int, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_SEARCH_FROM_BACKUP, Types._int, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS),
new HiddenField(Names.HIDDEN_TREGEX_MATCHING_MODE_BACKUP, Types.java_lang_Object, EspressoLanguage::useTRegex, NO_ADDITIONAL_FLAGS)
}),
entry(Types.com_oracle_truffle_espresso_polyglot_TypeLiteral, new HiddenField[]{
new HiddenField(Names.HIDDEN_INTERNAL_TYPE)}),
Expand Down
Loading