Skip to content

Commit ca079b5

Browse files
committed
style fixes
1 parent 735f732 commit ca079b5

File tree

5 files changed

+156
-69
lines changed

5 files changed

+156
-69
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@
2626

2727
import java.io.FileDescriptor;
2828
import java.io.FileOutputStream;
29-
import java.lang.reflect.Constructor;
30-
import java.lang.reflect.Executable;
31-
import java.lang.reflect.Field;
3229
import java.lang.reflect.InvocationTargetException;
3330
import java.lang.reflect.Member;
3431
import java.lang.reflect.Method;
35-
import java.util.ArrayList;
3632
import java.util.List;
3733
import java.util.regex.Matcher;
3834
import java.util.regex.Pattern;
@@ -275,8 +271,9 @@ public static String digest(String value) {
275271
}
276272

277273
/**
278-
* Convenience method that delegates to the corresponding method of the currently
279-
* registered UniqueShortNameProvider image singleton.
274+
* Convenience method that delegates to the corresponding method of the currently registered
275+
* UniqueShortNameProvider image singleton.
276+
*
280277
* @param m a method whose unique short name is required
281278
* @return a unique short name for the method
282279
*/
@@ -287,6 +284,7 @@ public static String uniqueShortName(ResolvedJavaMethod m) {
287284
/**
288285
* Delegate to the corresponding method of the currently registered UniqueShortNameProvider
289286
* image singleton.
287+
*
290288
* @param loaderName the unique loader id for some method's class loader
291289
* @param declaringClass the method's declaring class
292290
* @param methodName the method's name
@@ -301,6 +299,7 @@ public static String uniqueShortName(String loaderName, ResolvedJavaType declari
301299
/**
302300
* Delegate to the corresponding method of the currently registered UniqueShortNameProvider
303301
* image singleton.
302+
*
304303
* @param m a member whose unique short name is required
305304
* @return a unique short name for the member
306305
*/
@@ -311,6 +310,7 @@ public static String uniqueShortName(Member m) {
311310
/**
312311
* Delegate to the corresponding method of the currently registered UniqueShortNameProvider
313312
* image singleton.
313+
*
314314
* @param m a method whose unique stub name is required
315315
* @return a unique stub name for the method
316316
*/
@@ -321,6 +321,7 @@ public static String uniqueStubName(ResolvedJavaMethod m) {
321321
/**
322322
* Delegate to the corresponding method of the currently registered UniqueShortNameProvider
323323
* image singleton.
324+
*
324325
* @param loader a class loader whose identifier is required
325326
* @return A unique identifier for the class loader
326327
*/

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/UniqueShortNameProvider.java

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*
2+
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
125
package com.oracle.svm.core;
226

327
import com.oracle.svm.core.util.VMError;
@@ -14,10 +38,10 @@
1438
import java.lang.reflect.Method;
1539

1640
/**
17-
* An abstract provider class that defines a protocol for generating unique short names for
18-
* Java methods and fields which are compatible for use as local linker symbols. An instance
19-
* of this class may be registered as an image singleton in order to ensure that a specific
20-
* naming convention is adopted.
41+
* An abstract provider class that defines a protocol for generating unique short names for Java
42+
* methods and fields which are compatible for use as local linker symbols. An instance of this
43+
* class may be registered as an image singleton in order to ensure that a specific naming
44+
* convention is adopted.
2145
*/
2246
public abstract class UniqueShortNameProvider {
2347
private static UniqueShortNameProvider provider = null;
@@ -35,10 +59,11 @@ public static synchronized UniqueShortNameProvider provider() {
3559
}
3660

3761
/**
38-
* Returns a short, reasonably descriptive, but still unique name for the provided method
39-
* which can be used as a linker local symbol.
62+
* Returns a short, reasonably descriptive, but still unique name for the provided method which
63+
* can be used as a linker local symbol.
4064
*/
4165
public abstract String uniqueShortName(ResolvedJavaMethod method);
66+
4267
/**
4368
* Returns a short, reasonably descriptive, but still unique name for a method as characterized
4469
* by its loader name, owner class, method selector, signature and status as a method proper or
@@ -53,30 +78,33 @@ public static synchronized UniqueShortNameProvider provider() {
5378
public abstract String uniqueShortName(Member m);
5479

5580
/**
56-
* Returns a short, reasonably descriptive, but still unique name derived from the provided method
57-
* that can be used as the name of a stub method defined on some factory class that invokes it.
58-
* Note that although the value returned by this method is unique to the called method it's purpose
59-
* is to uniquely define a single component of the full name of the stub method i.e. the method
60-
* selector.
81+
* Returns a short, reasonably descriptive, but still unique name derived from the provided
82+
* method that can be used as the name of a stub method defined on some factory class that
83+
* invokes it. Note that although the value returned by this method is unique to the called
84+
* method it's purpose is to uniquely define a single component of the full name of the stub
85+
* method i.e. the method selector.
6186
*/
6287

6388
public abstract String uniqueStubName(ResolvedJavaMethod method);
89+
6490
/**
6591
* Returns a unique identifier for a class loader that can be folded into the unique short name
6692
* of methods where needed in order to disambiguate name collisions that can arise when the same
6793
* class bytecode is loaded by more than one loader. For a few special loaders, such as the JDK
6894
* runtime's builtin loaders and GraalVM Native's top level loaders an empty string is returned.
6995
* There is no need to qualify the method name in this case since the method defined via these
7096
* loaders is taken to be the primary instance. This is safe so long as the delegation model for
71-
* this special set of loaders ensures that none of them will replicate a class loaded by another
72-
* loader in the set.
97+
* this special set of loaders ensures that none of them will replicate a class loaded by
98+
* another loader in the set.
99+
*
73100
* @param loader The loader whose identifier is to be returned.
74-
* @return A unique identifier for the classloader or the empty string when the loader is one
75-
* of the special set whose method names do not need qualification.
101+
* @return A unique identifier for the classloader or the empty string when the loader is one of
102+
* the special set whose method names do not need qualification.
76103
*/
77104
public abstract String classLoaderNameAndId(ClassLoader loader);
78105

79106
private static final Field classLoaderNameAndId = ReflectionUtil.lookupField(ClassLoader.class, "nameAndId");
107+
80108
protected String lookupNameAndIdField(ClassLoader loader) {
81109
try {
82110
return (String) classLoaderNameAndId.get(loader);
@@ -86,20 +114,16 @@ protected String lookupNameAndIdField(ClassLoader loader) {
86114
}
87115

88116
/**
89-
* Default implementation for unique method and field short names which concatenates the (unqualified)
90-
* owner class name and method or field selector with an SHA1 digest of the fully qualified Java
91-
* name of the method or field. If a loader prefix is provided it is added as prefix to the Java
92-
* name before generating the SHA1 digest.
117+
* Default implementation for unique method and field short names which concatenates the
118+
* (unqualified) owner class name and method or field selector with an SHA1 digest of the fully
119+
* qualified Java name of the method or field. If a loader prefix is provided it is added as
120+
* prefix to the Java name before generating the SHA1 digest.
93121
*/
94122
private static class DefaultUniqueShortNameProvider extends UniqueShortNameProvider {
95123
@Override
96124
public String uniqueShortName(ResolvedJavaMethod m) {
97125
return uniqueShortName("", m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
98126
}
99-
public String uniqueStubName(ResolvedJavaMethod m) {
100-
// the default short name works as a name for the stub method
101-
return uniqueShortName("", m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
102-
}
103127

104128
@Override
105129
public String uniqueShortName(String loaderName, ResolvedJavaType declaringClass, String methodName, Signature methodSignature, boolean isConstructor) {
@@ -114,8 +138,8 @@ public String uniqueShortName(String loaderName, ResolvedJavaType declaringClass
114138
}
115139

116140
return stripPackage(declaringClass.toJavaName()) + "_" +
117-
(isConstructor ? "constructor" : methodName) + "_" +
118-
SubstrateUtil.digest(sb.toString());
141+
(isConstructor ? "constructor" : methodName) + "_" +
142+
SubstrateUtil.digest(sb.toString());
119143
}
120144

121145
@Override
@@ -139,14 +163,17 @@ public String uniqueShortName(Member m) {
139163
}
140164

141165
return stripPackage(m.getDeclaringClass().getTypeName()) + "_" +
142-
(m instanceof Constructor ? "constructor" : m.getName()) + "_" +
143-
SubstrateUtil.digest(fullName.toString());
166+
(m instanceof Constructor ? "constructor" : m.getName()) + "_" +
167+
SubstrateUtil.digest(fullName.toString());
144168
}
145-
private static String stripPackage(String qualifiedClassName) {
146-
/* Anonymous classes can contain a '/' which can lead to an invalid binary name. */
147-
return qualifiedClassName.substring(qualifiedClassName.lastIndexOf(".") + 1).replace("/", "");
169+
170+
@Override
171+
public String uniqueStubName(ResolvedJavaMethod m) {
172+
// the default short name works as a name for the stub method
173+
return uniqueShortName("", m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
148174
}
149175

176+
@Override
150177
public String classLoaderNameAndId(ClassLoader loader) {
151178
// no need to qualify classes loaded by a bootstrap loader
152179
if (loader == null) {
@@ -160,4 +187,10 @@ public String classLoaderNameAndId(ClassLoader loader) {
160187
return name;
161188
}
162189
}
190+
191+
private static String stripPackage(String qualifiedClassName) {
192+
/* Anonymous classes can contain a '/' which can lead to an invalid binary name. */
193+
return qualifiedClassName.substring(qualifiedClassName.lastIndexOf(".") + 1).replace("/", "");
194+
}
195+
163196
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it

0 commit comments

Comments
 (0)