@@ -27,94 +27,101 @@ namespace {
2727// followed by specified suffix chars and removing those. For example,
2828// calling the function with ("foo123bar", "foo", "321") returns "foobar".
2929template <size_t M, size_t N>
30- string SimplifySuffixedName (string name, const char (&trigger)[M],
31- const char (&suffix_chars)[N]) {
30+ void SimplifySuffixedName (string * name, const char (&trigger)[M],
31+ const char (&suffix_chars)[N]) {
3232 size_t first = 0 ;
33- while ((first = name. find (trigger, first)) != std::string::npos) {
33+ while ((first = name-> find (trigger, first)) != std::string::npos) {
3434 first += M - 1 ; // Exclude last zero char.
35- size_t last = name. find_first_not_of (suffix_chars, first, N);
35+ size_t last = name-> find_first_not_of (suffix_chars, first, N);
3636 if (last == std::string::npos) {
37- name. erase (first);
37+ name-> erase (first);
3838 break ;
3939 }
40- name. erase (first, last - first);
40+ name-> erase (first, last - first);
4141 }
42- return name;
4342}
4443
4544// Simplifies the name of a method in a dynamic class (with '$$FastClassBy*$$'
4645// or '$$EnhancedBy*$$' in its name) to make it more human readable, and group
4746// related functions under a single name. This could be done with a regexp
4847// replacement, but including RE2 increases the size of the agent.
49- string SimplifyDynamicClassName (string name) {
48+ void SimplifyDynamicClassName (string * name) {
5049 // Replace $$[0-9a-f]+ by $$ to remove unique values, for example in
5150 // $FastClassByCGLIB$$fd6bdf6d.invoke.
52- return SimplifySuffixedName (std::move ( name) , " $$" , " 0123456789abcdef" );
51+ SimplifySuffixedName (name, " $$" , " 0123456789abcdef" );
5352}
5453
5554// Simplifies the name of a lambda method to replace $$Lambda$[0-9]+\.[0-9]+ by
5655// $$Lambda$ to remove unique values, for example in
5756// com.google.something.Something$$Lambda$197.1849072452.run.
58- string SimplifyLambdaName (string name) {
57+ void SimplifyLambdaName (string * name) {
5958 constexpr char trigger[] = " $$Lambda$" ;
6059 constexpr char digits[] = " 0123456789" ;
6160 const size_t trigger_length = strlen (trigger);
6261
6362 // Assume and handle just one instance of a $$Lambda$ pattern.
64- size_t first = name. find (trigger);
63+ size_t first = name-> find (trigger);
6564 if (first == std::string::npos) {
66- return name ;
65+ return ;
6766 }
6867 first += trigger_length;
69- if (first >= name. size () || !isdigit (name[first])) {
70- return name ;
68+ if (first >= name-> size () || !isdigit ((* name) [first])) {
69+ return ;
7170 }
72- size_t last = name. find_first_not_of (digits, first);
73- if (last == std::string::npos || name[last] != ' .' ) {
74- return name ;
71+ size_t last = name-> find_first_not_of (digits, first);
72+ if (last == std::string::npos || (* name) [last] != ' .' ) {
73+ return ;
7574 }
7675 last++; // skip the dot
77- if (last >= name. size () || !isdigit (name[last])) {
78- return name ;
76+ if (last >= name-> size () || !isdigit ((* name) [last])) {
77+ return ;
7978 }
80- last = name. find_first_not_of (digits, last);
79+ last = name-> find_first_not_of (digits, last);
8180 if (last == std::string::npos) {
82- name. erase (first);
83- return name ;
81+ name-> erase (first);
82+ return ;
8483 }
85- name.erase (first, last - first);
86- return name;
84+ name->erase (first, last - first);
8785}
8886
8987constexpr char digits[] = " 0123456789" ;
9088
9189// Simplifies the name of a method generated by the runtime as a reflection
9290// stub. See the test file for examples, or generateName() in
9391// jdk/internal/reflect/MethodAccessorGenerator.java.
94- string SimplifyInternalReflectionMethodName (string name) {
95- return SimplifySuffixedName (
96- SimplifySuffixedName (
97- SimplifySuffixedName (
98- std::move (name),
99- " jdk.internal.reflect.GeneratedConstructorAccessor" ,
100- digits),
101- " jdk.internal.reflect.GeneratedMethodAccessor" ,
102- digits),
92+ void SimplifyInternalReflectionMethodName (string *name) {
93+ SimplifySuffixedName (
94+ name,
95+ " jdk.internal.reflect.GeneratedConstructorAccessor" ,
96+ digits);
97+
98+ SimplifySuffixedName (
99+ name,
100+ " jdk.internal.reflect.GeneratedMethodAccessor" ,
101+ digits);
102+
103+ SimplifySuffixedName (
104+ name,
103105 " jdk.internal.reflect.GeneratedSerializationConstructorAccessor" ,
104106 digits);
105107}
106108
107109// Simplifies the name of a method generated by the runtime as a reflection
108110// stub. See the test file for examples, or generateName() in
109111// sun/reflect/MethodAccessorGenerator.java.
110- string SimplifyReflectionMethodName (string name) {
111- return SimplifySuffixedName (
112- SimplifySuffixedName (
113- SimplifySuffixedName (std::move (name),
114- " sun.reflect.GeneratedConstructorAccessor" ,
115- digits),
116- " sun.reflect.GeneratedMethodAccessor" ,
117- digits),
112+ void SimplifyReflectionMethodName (string *name) {
113+ SimplifySuffixedName (
114+ name,
115+ " sun.reflect.GeneratedConstructorAccessor" ,
116+ digits);
117+
118+ SimplifySuffixedName (
119+ name,
120+ " sun.reflect.GeneratedMethodAccessor" ,
121+ digits);
122+
123+ SimplifySuffixedName (
124+ name,
118125 " sun.reflect.GeneratedSerializationConstructorAccessor" ,
119126 digits);
120127}
@@ -247,12 +254,11 @@ string ParseMethodTypeSignatureWithReturn(const char *buffer, int buffer_size,
247254
248255} // namespace
249256
250- string SimplifyFunctionName (const string& name) {
251- // The calls should be kept nested, without explicit string declarations, so
252- // that move semantics can be applied to minimize copies.
253- return SimplifyInternalReflectionMethodName (
254- SimplifyReflectionMethodName (
255- SimplifyLambdaName (SimplifyDynamicClassName (name))));
257+ void SimplifyFunctionName (string* name) {
258+ SimplifyDynamicClassName (name);
259+ SimplifyLambdaName (name);
260+ SimplifyReflectionMethodName (name);
261+ SimplifyInternalReflectionMethodName (name);
256262}
257263
258264void FixPath (string *s) {
0 commit comments