Skip to content

Commit

Permalink
more style fixes and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed May 17, 2023
1 parent c87b7bb commit bc83d12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ private int writeForeignFloatLayout(DebugContext context, ForeignTypeEntry forei
return writeStrSectionOffset(name, buffer, pos);
}

private String integralTypeName(int byteSize, boolean isSigned) {
private static String integralTypeName(int byteSize, boolean isSigned) {
assert (byteSize & (byteSize - 1)) == 0 : "expecting a power of 2!";
StringBuilder stringBuilder = new StringBuilder();
if (!isSigned) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public String bfdMangle(String loaderName, ResolvedJavaType declaringClass, Stri
* i.e. after "$_" for index 0, successive encodings for index i embded the base 36 digits for
* (i - 1) between "S" and "_".
*/
return new BFDMangler(this, nativeLibs).mangle(loaderName, declaringClass, memberName, methodSignature, isConstructor);
return new BFDMangler(this).mangle(loaderName, declaringClass, memberName, methodSignature, isConstructor);
}

/**
Expand All @@ -368,15 +368,15 @@ public String bfdMangle(String loaderName, ResolvedJavaType declaringClass, Stri
* @return a unique mangled name for the method
*/
public String bfdMangle(Member m) {
return new BFDMangler(this, nativeLibs).mangle(m);
return new BFDMangler(this).mangle(m);
}

/**
* Make the provider aware of the current native libraries. This is needed because the provider
* is created in a feature after registration but the native libraries are only available before
* analysis.
*
* @param nativeLibs the
* @param nativeLibs the current native libraries singleton.
*/
public void setNativeLibs(NativeLibraries nativeLibs) {
this.nativeLibs = nativeLibs;
Expand All @@ -386,13 +386,10 @@ private static class BFDMangler {
final NativeImageBFDNameProvider nameProvider;
final StringBuilder sb;
final List<String> prefixes;
final NativeLibraries nativeLibs;

BFDMangler(NativeImageBFDNameProvider provider, NativeLibraries libs) {
BFDMangler(NativeImageBFDNameProvider provider) {
nameProvider = provider;
sb = new StringBuilder("_Z");
prefixes = new ArrayList<>();
nativeLibs = libs;
}

public String mangle(String loaderName, ResolvedJavaType declaringClass, String memberName, Signature methodSignature, boolean isConstructor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
import jdk.vm.ci.meta.Signature;
import jdk.vm.ci.meta.Value;
import org.graalvm.nativeimage.c.struct.CPointerTo;
import org.graalvm.word.PointerBase;
import org.graalvm.word.WordBase;

/**
Expand All @@ -145,7 +144,6 @@ class NativeImageDebugInfoProvider implements DebugInfoProvider {
private final Set<HostedMethod> allOverrides;
HostedType hubType;
private HostedType wordBaseType;
private HostedType pointerBaseType;
HashMap<JavaKind, HostedType> javaKindToHostedType;

NativeImageDebugInfoProvider(DebugContext debugContext, NativeImageCodeCache codeCache, NativeImageHeap heap, NativeLibraries nativeLibs, HostedMetaAccess metaAccess) {
Expand Down Expand Up @@ -180,7 +178,6 @@ class NativeImageDebugInfoProvider implements DebugInfoProvider {
.collect(Collectors.toSet());
hubType = metaAccess.lookupJavaType(Class.class);
wordBaseType = metaAccess.lookupJavaType(WordBase.class);
pointerBaseType = metaAccess.lookupJavaType(PointerBase.class);
javaKindToHostedType = initJavaKindToHostedTypes(metaAccess);
}

Expand Down Expand Up @@ -872,12 +869,13 @@ public Stream<DebugFieldInfo> fieldInfoProvider() {
return orderedFieldsStream(elementInfo).map(this::createForeignDebugFieldInfo);
}

@Override
public int size() {
return elementSize(elementInfo);
}

DebugFieldInfo createForeignDebugFieldInfo(StructFieldInfo structFieldInfo) {
return new NativeImageForeignDebugFieldInfo(hostedType, elementInfo, structFieldInfo);
return new NativeImageForeignDebugFieldInfo(hostedType, structFieldInfo);
}

@Override
Expand Down Expand Up @@ -950,14 +948,10 @@ public ResolvedJavaType pointerTo() {
}

private class NativeImageForeignDebugFieldInfo extends NativeImageDebugFileInfo implements DebugInfoProvider.DebugFieldInfo {
HostedType hostedType;
ElementInfo elementInfo;
StructFieldInfo structFieldInfo;

NativeImageForeignDebugFieldInfo(HostedType hostedType, ElementInfo elementInfo, StructFieldInfo structFieldInfo) {
NativeImageForeignDebugFieldInfo(HostedType hostedType, StructFieldInfo structFieldInfo) {
super(hostedType);
this.hostedType = hostedType;
this.elementInfo = elementInfo;
this.structFieldInfo = structFieldInfo;
}

Expand All @@ -980,7 +974,7 @@ public String name() {
public ResolvedJavaType valueType() {
// we need to ensure the hosted type identified for the field value gets translated to
// an original in order to be consistent with id types for substitutions
return getOriginal(getFieldType(hostedType, structFieldInfo));
return getOriginal(getFieldType(structFieldInfo));
}

@Override
Expand Down Expand Up @@ -1194,7 +1188,7 @@ private void logStructInfo(HostedType hostedType, StructInfo structInfo) {
int nextSize = elementSize(field);
assert nextOffset > currentOffset : "raw struct has two fields at same offset " + currentOffset;
String fieldName = field.getName();
ResolvedJavaType type = getFieldType(hostedType, field);
ResolvedJavaType type = getFieldType(field);
debugContext.log(" %s %s;", type.toJavaName(), fieldName);
totalSize += nextSize;
}
Expand Down Expand Up @@ -1231,7 +1225,7 @@ private void logRawStructureInfo(HostedType hostedType, RawStructureInfo rawStru
int nextSize = elementSize(field);
assert nextOffset > currentOffset : "raw struct has two fields at same offset " + currentOffset;
String fieldName = field.getName();
ResolvedJavaType type = getFieldType(hostedType, field);
ResolvedJavaType type = getFieldType(field);
debugContext.log(" %s %s;", type.toJavaName(), fieldName);
totalSize += nextSize;
}
Expand All @@ -1241,7 +1235,7 @@ private void logRawStructureInfo(HostedType hostedType, RawStructureInfo rawStru
debugContext.log(" } %s;", rawStructureInfo.getName());
}

private HostedType getFieldType(HostedType hostedType, StructFieldInfo field) {
private HostedType getFieldType(StructFieldInfo field) {
// we should always some sort of accessor, preferably a GETTER or a SETTER
// but possibly an ADDRESS accessor or even just an OFFSET accessor
for (ElementInfo elt : field.getChildren()) {
Expand Down Expand Up @@ -1284,7 +1278,7 @@ int elementSize(ElementInfo elementInfo) {
return size;
}

String elementName(ElementInfo elementInfo) {
private static String elementName(ElementInfo elementInfo) {
if (elementInfo == null) {
return "";
} else {
Expand Down Expand Up @@ -1329,13 +1323,13 @@ private void dumpElementInfo(ElementInfo elementInfo) {
}
}

private String formatElementInfo(ElementInfo elementInfo) {
private static String formatElementInfo(ElementInfo elementInfo) {
StringBuilder stringBuilder = new StringBuilder();
formatElementInfo(elementInfo, stringBuilder, 0);
return stringBuilder.toString();
}

private void formatElementInfo(ElementInfo elementInfo, StringBuilder stringBuilder, int indent) {
private static void formatElementInfo(ElementInfo elementInfo, StringBuilder stringBuilder, int indent) {
indentElementInfo(stringBuilder, indent);
formatSingleElement(elementInfo, stringBuilder);
List<ElementInfo> children = elementInfo.getChildren();
Expand All @@ -1351,7 +1345,7 @@ private void formatElementInfo(ElementInfo elementInfo, StringBuilder stringBuil
}
}

private void formatSingleElement(ElementInfo elementInfo, StringBuilder stringBuilder) {
private static void formatSingleElement(ElementInfo elementInfo, StringBuilder stringBuilder) {
stringBuilder.append(ClassUtil.getUnqualifiedName(elementInfo.getClass()));
stringBuilder.append(" : ");
stringBuilder.append(elementName(elementInfo));
Expand All @@ -1361,11 +1355,11 @@ private void formatSingleElement(ElementInfo elementInfo, StringBuilder stringBu
}
}

private <T> void formatPropertyInfo(PropertyInfo<T> propertyInfo, StringBuilder stringBuilder) {
private static <T> void formatPropertyInfo(PropertyInfo<T> propertyInfo, StringBuilder stringBuilder) {
stringBuilder.append(propertyInfo.getProperty());
}

private void indentElementInfo(StringBuilder stringBuilder, int indent) {
private static void indentElementInfo(StringBuilder stringBuilder, int indent) {
for (int i = 0; i <= indent; i++) {
stringBuilder.append(" ");
}
Expand Down Expand Up @@ -1606,45 +1600,30 @@ private List<DebugLocalInfo> createParamInfo(ResolvedJavaMethod method, int line
*/
private boolean isForeignWordType(JavaType type, ResolvedJavaType accessingType) {
assert accessingType instanceof HostedType : "must be!";
ResolvedJavaType resolvedJavaType = type.resolve(accessingType);
HostedType resolvedJavaType = (HostedType) type.resolve(accessingType);
return isForeignWordType(resolvedJavaType);
}

/**
* Identify a hosted type which is being used to model a foreign memory word or pointer type.
*
* @param resolvedJavaType the type to be tested which must be an instance of HostedType
* @param hostedType the type to be tested
* @return true if the type models a foreign memory word or pointer type
*/
private boolean isForeignWordType(ResolvedJavaType resolvedJavaType) {
assert resolvedJavaType instanceof HostedType : "must be!";
private boolean isForeignWordType(HostedType hostedType) {
// unwrap because native libs operates on the analysis type universe
return nativeLibs.isWordBase(((HostedType) resolvedJavaType).getWrapped());
}

/**
* Identify a Java type which is being used to model a foreign pointer type.
*
* @param type the type to be tested
* @param accessingType another type relative to which the first type may need to be resolved
* @return true if the type models a foreign pointer type
*/
private boolean isForeignPointerType(JavaType type, ResolvedJavaType accessingType) {
assert accessingType instanceof HostedType : "must be!";
ResolvedJavaType resolvedJavaType = type.resolve(accessingType);
return isForeignPointerType(resolvedJavaType);
return nativeLibs.isWordBase(hostedType.getWrapped());
}

/**
* Identify a hosted type which is being used to model a foreign pointer type.
*
* @param resolvedJavaType the type to be tested which must be an instance of HostedType
* @param hostedType the type to be tested
* @return true if the type models a foreign pointer type
*/
private boolean isForeignPointerType(ResolvedJavaType resolvedJavaType) {
assert resolvedJavaType instanceof HostedType : "must be!";
private boolean isForeignPointerType(HostedType hostedType) {
// unwrap because native libs operates on the analysis type universe
return nativeLibs.isPointerBase(((HostedType) resolvedJavaType).getWrapped());
return nativeLibs.isPointerBase(hostedType.getWrapped());
}

private static boolean isIntegralKindPromotion(JavaKind promoted, JavaKind original) {
Expand Down

0 comments on commit bc83d12

Please sign in to comment.