Commit 46e54fb3 authored by Andrew Grieve's avatar Andrew Grieve Committed by Chromium LUCI CQ

jni_generator.py: Include hashed name as comment when not in use

Codesearch indexes with is_java_debug=true, so this change will allow
looking up method hashes via codesearch.

Bug: None
Change-Id: I1d8d841073c5ef502d1e1b421a411894776e4cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2636297
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844784}
parent 69f5a0f9
......@@ -11,39 +11,40 @@ package J;
public class N {
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_foo
public static native void MygCV2jQ();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_bar
public static native Object MHuqnmXT(Object sample);
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_revString
public static native String MM5Xkwyy(String stringToReverse);
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendToNative
public static native String[] MAC2QhR9(String[] strs);
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendSamplesToNative
public static native Object[] MGhRh4Nd(Object[] strs);
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_hasPhalange
public static native boolean MW0aEs4h();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testAllPrimitives
public static native int[] MlVFI4RX(int zint, int[] ints, long zlong, long[] longs, short zshort, short[] shorts, char zchar, char[] chars, byte zbyte, byte[] bytes, double zdouble, double[] doubles, float zfloat, float[] floats, boolean zbool, boolean[] bools);
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testSpecialTypes
public static native void MqOnlud7(Class clazz, Class[] classes, Throwable throwable, Throwable[] throwables, String string, String[] strings, Object tStruct, Object[] structs, Object obj, Object[] objects);
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowable
public static native Throwable MuZc76Vt();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowables
public static native Throwable[] MAD53J7V();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClass
public static native Class M$ZgOi4g();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClasses
public static native Class[] M$hL1577();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnString
public static native String M0k1OjBK();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStrings
public static native String[] Mssfs54E();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStruct
public static native Object MSzcel_H();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStructs
public static native Object[] MIBrQLK4();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObject
public static native Object M$hPywjv();
// Original name: org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObjects
public static native Object[] MPpCU1l5();
}
......@@ -13,39 +13,40 @@ public class GEN_JNI {
public static final boolean REQUIRE_MOCK = false;
// Hashed name: MygCV2jQ
public static native void org_chromium_example_jni_1generator_SampleForAnnotationProcessor_foo();
// Hashed name: MHuqnmXT
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_bar(Object sample);
// Hashed name: MM5Xkwyy
public static native String org_chromium_example_jni_1generator_SampleForAnnotationProcessor_revString(String stringToReverse);
// Hashed name: MAC2QhR9
public static native String[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendToNative(String[] strs);
// Hashed name: MGhRh4Nd
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendSamplesToNative(Object[] strs);
// Hashed name: MW0aEs4h
public static native boolean org_chromium_example_jni_1generator_SampleForAnnotationProcessor_hasPhalange();
// Hashed name: MlVFI4RX
public static native int[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testAllPrimitives(int zint, int[] ints, long zlong, long[] longs, short zshort, short[] shorts, char zchar, char[] chars, byte zbyte, byte[] bytes, double zdouble, double[] doubles, float zfloat, float[] floats, boolean zbool, boolean[] bools);
// Hashed name: MqOnlud7
public static native void org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testSpecialTypes(Class clazz, Class[] classes, Throwable throwable, Throwable[] throwables, String string, String[] strings, Object tStruct, Object[] structs, Object obj, Object[] objects);
// Hashed name: MuZc76Vt
public static native Throwable org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowable();
// Hashed name: MAD53J7V
public static native Throwable[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowables();
// Hashed name: M$ZgOi4g
public static native Class org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClass();
// Hashed name: M$hL1577
public static native Class[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClasses();
// Hashed name: M0k1OjBK
public static native String org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnString();
// Hashed name: Mssfs54E
public static native String[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStrings();
// Hashed name: MSzcel_H
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStruct();
// Hashed name: MIBrQLK4
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStructs();
// Hashed name: M$hPywjv
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObject();
// Hashed name: MPpCU1l5
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObjects();
}
......@@ -13,39 +13,40 @@ public class GEN_JNI {
public static final boolean REQUIRE_MOCK = false;
// Hashed name: MygCV2jQ
public static native void org_chromium_example_jni_1generator_SampleForAnnotationProcessor_foo();
// Hashed name: MHuqnmXT
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_bar(Object sample);
// Hashed name: MM5Xkwyy
public static native String org_chromium_example_jni_1generator_SampleForAnnotationProcessor_revString(String stringToReverse);
// Hashed name: MAC2QhR9
public static native String[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendToNative(String[] strs);
// Hashed name: MGhRh4Nd
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendSamplesToNative(Object[] strs);
// Hashed name: MW0aEs4h
public static native boolean org_chromium_example_jni_1generator_SampleForAnnotationProcessor_hasPhalange();
// Hashed name: MlVFI4RX
public static native int[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testAllPrimitives(int zint, int[] ints, long zlong, long[] longs, short zshort, short[] shorts, char zchar, char[] chars, byte zbyte, byte[] bytes, double zdouble, double[] doubles, float zfloat, float[] floats, boolean zbool, boolean[] bools);
// Hashed name: MqOnlud7
public static native void org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testSpecialTypes(Class clazz, Class[] classes, Throwable throwable, Throwable[] throwables, String string, String[] strings, Object tStruct, Object[] structs, Object obj, Object[] objects);
// Hashed name: MuZc76Vt
public static native Throwable org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowable();
// Hashed name: MAD53J7V
public static native Throwable[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowables();
// Hashed name: M$ZgOi4g
public static native Class org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClass();
// Hashed name: M$hL1577
public static native Class[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClasses();
// Hashed name: M0k1OjBK
public static native String org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnString();
// Hashed name: Mssfs54E
public static native String[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStrings();
// Hashed name: MSzcel_H
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStruct();
// Hashed name: MIBrQLK4
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStructs();
// Hashed name: M$hPywjv
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObject();
// Hashed name: MPpCU1l5
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObjects();
}
......@@ -13,39 +13,40 @@ public class GEN_JNI {
public static final boolean REQUIRE_MOCK = true;
// Hashed name: MygCV2jQ
public static native void org_chromium_example_jni_1generator_SampleForAnnotationProcessor_foo();
// Hashed name: MHuqnmXT
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_bar(Object sample);
// Hashed name: MM5Xkwyy
public static native String org_chromium_example_jni_1generator_SampleForAnnotationProcessor_revString(String stringToReverse);
// Hashed name: MAC2QhR9
public static native String[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendToNative(String[] strs);
// Hashed name: MGhRh4Nd
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_sendSamplesToNative(Object[] strs);
// Hashed name: MW0aEs4h
public static native boolean org_chromium_example_jni_1generator_SampleForAnnotationProcessor_hasPhalange();
// Hashed name: MlVFI4RX
public static native int[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testAllPrimitives(int zint, int[] ints, long zlong, long[] longs, short zshort, short[] shorts, char zchar, char[] chars, byte zbyte, byte[] bytes, double zdouble, double[] doubles, float zfloat, float[] floats, boolean zbool, boolean[] bools);
// Hashed name: MqOnlud7
public static native void org_chromium_example_jni_1generator_SampleForAnnotationProcessor_testSpecialTypes(Class clazz, Class[] classes, Throwable throwable, Throwable[] throwables, String string, String[] strings, Object tStruct, Object[] structs, Object obj, Object[] objects);
// Hashed name: MuZc76Vt
public static native Throwable org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowable();
// Hashed name: MAD53J7V
public static native Throwable[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnThrowables();
// Hashed name: M$ZgOi4g
public static native Class org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClass();
// Hashed name: M$hL1577
public static native Class[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnClasses();
// Hashed name: M0k1OjBK
public static native String org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnString();
// Hashed name: Mssfs54E
public static native String[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStrings();
// Hashed name: MSzcel_H
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStruct();
// Hashed name: MIBrQLK4
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnStructs();
// Hashed name: M$hPywjv
public static native Object org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObject();
// Hashed name: MPpCU1l5
public static native Object[] org_chromium_example_jni_1generator_SampleForAnnotationProcessor_returnObjects();
}
......@@ -13,9 +13,10 @@ public class GEN_JNI {
public static final boolean REQUIRE_MOCK = false;
// Hashed name: MfuvK7$r
public static native void org_chromium_example_SampleProxyJni_foo(long nativePtr);
// Hashed name: MB1mTV9a
public static native int org_chromium_example_SampleProxyJni_bar(int x, int y);
// Hashed name: Me7X4JzV
public static native String org_chromium_example_SampleProxyJni_foobar(String x, String y);
}
......@@ -140,18 +140,19 @@ class NativeMethod(object):
self.name = self.name[0].upper() + self.name[1:]
self.proxy_name = kwargs.get('proxy_name', self.name)
# Non-hashed proxy name if applicable.
self.proxy_name_orig = None
self.hashed_proxy_name = kwargs.get('hashed_proxy_name', None)
if self.params:
assert type(self.params) is list
assert type(self.params[0]) is Param
if (self.params
and self.params[0].datatype == kwargs.get('ptr_type', 'int')
ptr_type = kwargs.get('ptr_type', 'int')
if (self.params and self.params[0].datatype == ptr_type
and self.params[0].name.startswith('native')):
self.ptr_type = ptr_type
self.type = 'method'
self.p0_type = kwargs.get('p0_type')
if self.p0_type is None:
self.p0_type = self.params[0].name[len('native'):]
if kwargs.get('native_class_name'):
self.p0_type = kwargs['native_class_name']
......@@ -900,10 +901,7 @@ class ProxyHelpers(object):
return EscapeClassName(fully_qualified_class + '/' + old_name)
@staticmethod
def ExtractStaticProxyNatives(fully_qualified_class,
contents,
ptr_type,
use_hash=False):
def ExtractStaticProxyNatives(fully_qualified_class, contents, ptr_type):
methods = []
for match in _NATIVE_PROXY_EXTRACTION_REGEX.finditer(contents):
interface_body = match.group('interface_body')
......@@ -911,8 +909,11 @@ class ProxyHelpers(object):
name = method.group('name')
params = JniParams.Parse(method.group('params'), use_proxy_types=True)
return_type = JavaTypeToProxyCast(method.group('return_type'))
unescaped_proxy_name = ProxyHelpers.CreateProxyMethodName(
fully_qualified_class, name, use_hash)
proxy_name = ProxyHelpers.CreateProxyMethodName(fully_qualified_class,
name,
use_hash=False)
hashed_proxy_name = ProxyHelpers.CreateProxyMethodName(
fully_qualified_class, name, use_hash=True)
native = NativeMethod(
static=True,
java_class_name=None,
......@@ -921,11 +922,9 @@ class ProxyHelpers(object):
native_class_name=method.group('native_class_name'),
params=params,
is_proxy=True,
proxy_name=unescaped_proxy_name,
proxy_name=proxy_name,
hashed_proxy_name=hashed_proxy_name,
ptr_type=ptr_type)
if use_hash:
native.proxy_name_orig = ProxyHelpers.CreateProxyMethodName(
fully_qualified_class, name, False)
methods.append(native)
return methods
......@@ -943,9 +942,9 @@ class JNIFromJavaSource(object):
called_by_natives = ExtractCalledByNatives(self.jni_params, contents,
options.always_mangle)
natives += ProxyHelpers.ExtractStaticProxyNatives(
fully_qualified_class, contents, options.ptr_type,
options.use_proxy_hash)
natives += ProxyHelpers.ExtractStaticProxyNatives(fully_qualified_class,
contents,
options.ptr_type)
if len(natives) == 0 and len(called_by_natives) == 0:
raise SyntaxError(
......@@ -987,6 +986,9 @@ class HeaderFileGeneratorHelper(object):
A string with the stub function name (used by the JVM).
"""
if native.is_proxy:
if self.use_proxy_hash:
method_name = EscapeClassName(native.hashed_proxy_name)
else:
method_name = EscapeClassName(native.proxy_name)
return 'Java_%s_%s' % (EscapeClassName(
ProxyHelpers.GetQualifiedClass(self.use_proxy_hash)), method_name)
......
......@@ -37,6 +37,14 @@ _JAVA_SRC_DIR = os.path.join('java', 'src', 'org', 'chromium', 'example',
_REBASELINE_ENV = 'REBASELINE'
def _RemoveHashedNames(natives):
ret = []
for n in natives:
ret.append(jni_generator.NativeMethod(**n.__dict__))
ret[-1].hashed_proxy_name = None
return ret
class TestOptions(object):
"""The mock options object which is passed to the jni_generator.py script."""
......@@ -1350,7 +1358,7 @@ class ProxyTestGenerator(BaseTest):
proxy_name='org_chromium_example_SampleProxyJni_foo_1_1bar'),
]
self.AssertListEquals(natives, golden_natives)
self.AssertListEquals(_RemoveHashedNames(natives), golden_natives)
def testProxyNativesMainDex(self):
test_data = """
......@@ -1392,7 +1400,7 @@ class ProxyTestGenerator(BaseTest):
proxy_name='test_foo_Foo_thisismaindex'),
]
self.AssertListEquals(natives, golden_natives)
self.AssertListEquals(_RemoveHashedNames(natives), golden_natives)
jni_params = jni_generator.JniParams(qualified_clazz)
main_dex_header = jni_registration_generator.HeaderGenerator(
......@@ -1502,8 +1510,9 @@ class ProxyTestGenerator(BaseTest):
is_proxy=True,
proxy_name='org_chromium_example_SampleProxyJni_foobar'),
]
self.AssertListEquals(golden_natives, natives)
self.AssertListEquals(golden_natives, bad_spacing_natives)
self.AssertListEquals(golden_natives, _RemoveHashedNames(natives))
self.AssertListEquals(golden_natives,
_RemoveHashedNames(bad_spacing_natives))
jni_params = jni_generator.JniParams(qualified_clazz)
h1 = jni_generator.InlHeaderFileGenerator('', qualified_clazz, natives, [],
......@@ -1635,7 +1644,7 @@ class ProxyTestGenerator(BaseTest):
proxy_name='org_chromium_foo_FooJni_bazProxy',
ptr_type='long')
]
self.AssertListEquals(golden_natives, natives)
self.AssertListEquals(golden_natives, _RemoveHashedNames(natives))
def TouchStamp(stamp_path):
......
......@@ -117,8 +117,7 @@ def _DictForPath(path, use_proxy_hash=False):
natives += jni_generator.ProxyHelpers.ExtractStaticProxyNatives(
fully_qualified_class=fully_qualified_class,
contents=contents,
ptr_type='long',
use_hash=use_proxy_hash)
ptr_type='long')
if len(natives) == 0:
return None
namespace = jni_generator.ExtractJNINamespace(contents)
......@@ -339,8 +338,9 @@ class HeaderGenerator(object):
self._AddRegisterNativesCalls()
self._AddRegisterNativesFunctions()
self.registration_dict['PROXY_NATIVE_SIGNATURES'] = ('\n'.join(
_MakeProxySignature(n) for n in self.proxy_natives))
self.registration_dict['PROXY_NATIVE_SIGNATURES'] = (''.join(
_MakeProxySignature(n, self.use_proxy_hash)
for n in self.proxy_natives))
if self.use_proxy_hash:
self.registration_dict['FORWARDING_PROXY_METHODS'] = ('\n'.join(
_MakeForwardingProxy(n) for n in self.proxy_natives))
......@@ -432,6 +432,9 @@ ${KMETHODS}
if native.is_proxy:
# Literal name of the native method in the class that contains the actual
# native declaration.
if self.use_proxy_hash:
name = native.hashed_proxy_name
else:
name = native.proxy_name
values = {
'NAME':
......@@ -537,8 +540,8 @@ ${NATIVES}\
def _MakeForwardingProxy(proxy_native):
template = string.Template("""
public static ${RETURN_TYPE} ${ORIG_NAME}(${PARAMS_WITH_TYPES}) {
${MAYBE_RETURN}${PROXY_CLASS}.${NAME}($PARAM_NAMES);
public static ${RETURN_TYPE} ${METHOD_NAME}(${PARAMS_WITH_TYPES}) {
${MAYBE_RETURN}${PROXY_CLASS}.${HASHED_NAME}($PARAM_NAMES);
}""")
params_with_types = ', '.join(
......@@ -549,32 +552,44 @@ def _MakeForwardingProxy(proxy_native):
return template.substitute({
'RETURN_TYPE':
proxy_native.return_type,
'ORIG_NAME':
proxy_native.proxy_name_orig,
'METHOD_NAME':
proxy_native.proxy_name,
'PARAMS_WITH_TYPES':
params_with_types,
'MAYBE_RETURN':
'' if proxy_native.return_type == 'void' else 'return ',
'PROXY_CLASS':
proxy_class.replace('/', '.'),
'NAME':
proxy_native.proxy_name,
'HASHED_NAME':
proxy_native.hashed_proxy_name,
'PARAM_NAMES':
param_names,
})
def _MakeProxySignature(proxy_native):
def _MakeProxySignature(proxy_native, use_proxy_hash):
if use_proxy_hash:
signature_template = string.Template("""
// Original name: ${ALT_NAME}
public static native ${RETURN_TYPE} ${NAME}(${PARAMS_WITH_TYPES});""")
else:
signature_template = string.Template("""
// Hashed name: ${ALT_NAME}
public static native ${RETURN_TYPE} ${NAME}(${PARAMS_WITH_TYPES});""")
params_with_types = ', '.join(
'%s %s' % (p.datatype, p.name) for p in proxy_native.params)
return signature_template.substitute({
args = {
'RETURN_TYPE': proxy_native.return_type,
'NAME': proxy_native.proxy_name,
'PARAMS_WITH_TYPES': params_with_types,
})
}
if use_proxy_hash:
args['NAME'] = proxy_native.hashed_proxy_name
args['ALT_NAME'] = proxy_native.proxy_name
else:
args['NAME'] = proxy_native.proxy_name
args['ALT_NAME'] = proxy_native.hashed_proxy_name
return signature_template.substitute(args)
class ProxyOptions:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment