Skip to content

Commit

Permalink
Register resource bundles as called, not returned
Browse files Browse the repository at this point in the history
  • Loading branch information
loicottet committed Nov 13, 2023
1 parent 2e61c28 commit fba956c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,18 +679,10 @@ private static boolean getBundleImpl(JNIEnvironment jni, JNIObjectHandle thread,
callerMethod = state.getCallerMethod(3);
}
JNIObjectHandle callerClass = getMethodDeclaringClass(callerMethod);
JNIObjectHandle callerModule = getObjectArgument(thread, 0);
JNIObjectHandle module = getObjectArgument(thread, 1);
JNIObjectHandle baseName = getObjectArgument(thread, 2);
JNIObjectHandle locale = getObjectArgument(thread, 3);
JNIObjectHandle control = getObjectArgument(thread, 4);
JNIObjectHandle result = Support.callStaticObjectMethodLLLLL(jni, bp.clazz, bp.method, callerModule, module, baseName, locale, control);
BundleInfo bundleInfo = BundleInfo.NONE;
if (!clearException(jni)) {
bundleInfo = extractBundleInfo(jni, result);
}
traceReflectBreakpoint(jni, nullHandle(), nullHandle(), callerClass, "getBundleImpl", true, state.getFullStackTraceOrNull(),
Tracer.UNKNOWN_VALUE, Tracer.UNKNOWN_VALUE, fromJniString(jni, baseName), Tracer.UNKNOWN_VALUE, Tracer.UNKNOWN_VALUE, bundleInfo.classNames, bundleInfo.locales);
traceReflectBreakpoint(jni, nullHandle(), nullHandle(), callerClass, bp.specification.methodName, true, state.getFullStackTraceOrNull(),
Tracer.UNKNOWN_VALUE, Tracer.UNKNOWN_VALUE, fromJniString(jni, baseName), readLocaleTag(jni, locale), Tracer.UNKNOWN_VALUE);
return true;
}

Expand All @@ -703,59 +695,6 @@ private static String readLocaleTag(JNIEnvironment jni, JNIObjectHandle locale)
return fromJniString(jni, languageTag);
}

private static final class BundleInfo {

static final BundleInfo NONE = new BundleInfo(new String[0], new String[0]);

final String[] classNames;
final String[] locales;

BundleInfo(String[] classNames, String[] locales) {
this.classNames = classNames;
this.locales = locales;
}
}

/**
* Traverses the bundle parent chain and collects classnames and locales of all encountered
* bundles.
*
*/
private static BundleInfo extractBundleInfo(JNIEnvironment jni, JNIObjectHandle bundle) {
List<String> locales = new ArrayList<>();
List<String> classNames = new ArrayList<>();
JNIObjectHandle curr = bundle;
while (curr.notEqual(nullHandle())) {
JNIObjectHandle locale = Support.callObjectMethod(jni, curr, agent.handles().getJavaUtilResourceBundleGetLocale(jni));
if (clearException(jni)) {
return BundleInfo.NONE;
}
String localeTag = readLocaleTag(jni, locale);
if (localeTag.equals("und")) {
/*- Root locale is serialized into "und" */
localeTag = "";
}
JNIObjectHandle clazz = Support.callObjectMethod(jni, curr, agent.handles().javaLangObjectGetClass);
if (!clearException(jni)) {
JNIObjectHandle classNameHandle = Support.callObjectMethod(jni, clazz, agent.handles().javaLangClassGetName);
if (!clearException(jni)) {
classNames.add(fromJniString(jni, classNameHandle));
locales.add(localeTag);
}
}
curr = getResourceBundleParent(jni, curr);
}
return new BundleInfo(classNames.toArray(new String[0]), locales.toArray(new String[0]));
}

private static JNIObjectHandle getResourceBundleParent(JNIEnvironment jni, JNIObjectHandle bundle) {
JNIObjectHandle parent = Support.readObjectField(jni, bundle, agent.handles().getJavaUtilResourceBundleParentField(jni));
if (!clearException(jni)) {
return parent;
}
return nullHandle();
}

private static boolean loadClass(JNIEnvironment jni, JNIObjectHandle thread, Breakpoint bp, InterceptedState state) {
assert experimentalClassLoaderSupport;
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
Expand All @@ -48,8 +47,6 @@

public final class ResourceConfiguration extends ConfigurationBase<ResourceConfiguration, ResourceConfiguration.Predicate> {

private static final String PROPERTY_BUNDLE = "java.util.PropertyResourceBundle";

public static class ParserAdapter implements ResourcesRegistry {

private final ResourceConfiguration configuration;
Expand Down Expand Up @@ -195,18 +192,9 @@ private void addClassResourceBundle(ConfigurationCondition condition, String bas
getOrCreateBundleConfig(condition, basename).classNames.add(className);
}

public void addBundle(ConfigurationCondition condition, List<String> classNames, List<String> locales, String baseName) {
assert classNames.size() == locales.size() : "Each bundle should be represented by both classname and locale";
public void addBundle(ConfigurationCondition condition, String baseName, String queriedLocale) {
BundleConfiguration config = getOrCreateBundleConfig(condition, baseName);
for (int i = 0; i < classNames.size(); i++) {
String className = classNames.get(i);
String localeTag = locales.get(i);
if (!className.equals(PROPERTY_BUNDLE)) {
config.classNames.add(className);
} else {
config.locales.add(localeTag);
}
}
config.locales.add(queriedLocale);
}

private BundleConfiguration getOrCreateBundleConfig(ConfigurationCondition condition, String baseName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,11 @@ public void processEntry(EconomicMap<String, ?> entry, ConfigurationSet configur
}

case "getBundleImpl": {
expectSize(args, 7);
expectSize(args, 5);
String baseName = (String) args.get(2);
@SuppressWarnings("unchecked")
List<String> classNames = (List<String>) args.get(5);
@SuppressWarnings("unchecked")
List<String> locales = (List<String>) args.get(6);
String queriedLocale = (String) args.get(3);
if (baseName != null) {
resourceConfiguration.addBundle(condition, classNames, locales, baseName);
resourceConfiguration.addBundle(condition, baseName, queriedLocale);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,29 +367,6 @@ public static JNIObjectHandle callStaticObjectMethodLLL(JNIEnvironment env, JNIO
return jniFunctions().getCallStaticObjectMethodA().invoke(env, clazz, method, args);
}

public static JNIObjectHandle callStaticObjectMethodLLLL(JNIEnvironment env, JNIObjectHandle clazz, JNIMethodId method,
JNIObjectHandle l0, JNIObjectHandle l1, JNIObjectHandle l2, JNIObjectHandle l3) {

JNIValue args = StackValue.get(4, JNIValue.class);
args.addressOf(0).setObject(l0);
args.addressOf(1).setObject(l1);
args.addressOf(2).setObject(l2);
args.addressOf(3).setObject(l3);
return jniFunctions().getCallStaticObjectMethodA().invoke(env, clazz, method, args);
}

public static JNIObjectHandle callStaticObjectMethodLLLLL(JNIEnvironment env, JNIObjectHandle clazz, JNIMethodId method,
JNIObjectHandle l0, JNIObjectHandle l1, JNIObjectHandle l2, JNIObjectHandle l3, JNIObjectHandle l4) {

JNIValue args = StackValue.get(5, JNIValue.class);
args.addressOf(0).setObject(l0);
args.addressOf(1).setObject(l1);
args.addressOf(2).setObject(l2);
args.addressOf(3).setObject(l3);
args.addressOf(4).setObject(l4);
return jniFunctions().getCallStaticObjectMethodA().invoke(env, clazz, method, args);
}

public static void callStaticVoidMethodLL(JNIEnvironment env, JNIObjectHandle clazz, JNIMethodId method, JNIObjectHandle l0, JNIObjectHandle l1) {
JNIValue args = StackValue.get(2, JNIValue.class);
args.addressOf(0).setObject(l0);
Expand Down

0 comments on commit fba956c

Please sign in to comment.