Skip to content

Commit

Permalink
revert language attribute and fix docs/style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Sep 14, 2022
1 parent de67018 commit 47e81a3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ public class DwarfDebugInfo extends DebugInfoBase {
* Value for DW_AT_language attribute with form DATA1.
*/
public static final byte DW_LANG_Java = 0xb;
public static final byte DW_LANG_C_plus_plus = 0x4;
public static final byte SELECTED_LANG_ENCODING = DW_LANG_C_plus_plus;
/**
* This field defines the value used for the DW_AT_language attribute of compile units.
*
*/
public static final byte LANG_ENCODING = DW_LANG_Java;
/*
* Values for {@link DW_AT_inline} attribute with form DATA1.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private int writeBuiltInUnit(DebugContext context, byte[] buffer, int p) {
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
pos = writeAbbrevCode(abbrevCode, buffer, pos);
log(context, " [0x%08x] language %s", pos, "DW_LANG_Java");
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);

/* Write child entries for basic Java types. */

Expand Down Expand Up @@ -351,7 +351,7 @@ private int writeNonCompiledClassUnit(DebugContext context, ClassEntry classEntr
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
pos = writeAbbrevCode(abbrevCode, buffer, pos);
log(context, " [0x%08x] language %s", pos, "DW_LANG_Java");
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
log(context, " [0x%08x] use_UTF8", pos);
pos = writeFlag((byte) 1, buffer, pos);
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(classEntry.getFileName()), classEntry.getFileName());
Expand Down Expand Up @@ -420,7 +420,7 @@ private int writeCompiledClassUnit(DebugContext context, ClassEntry classEntry,
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
pos = writeAbbrevCode(abbrevCode, buffer, pos);
log(context, " [0x%08x] language %s", pos, "DW_LANG_Java");
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
log(context, " [0x%08x] use_UTF8", pos);
pos = writeFlag((byte) 1, buffer, pos);
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(fileName), fileName);
Expand Down Expand Up @@ -658,7 +658,6 @@ private int writeMethodDeclarations(DebugContext context, ClassEntry classEntry,
private int writeMethodDeclaration(DebugContext context, ClassEntry classEntry, MethodEntry method, byte[] buffer, int p) {
int pos = p;
String methodKey = method.getSymbolName();
// String linkageName = uniqueDebugString(classEntry.getTypeName() + "::" + method.methodName());
String linkageName = uniqueDebugString(methodKey);
setMethodDeclarationIndex(method, pos);
int modifiers = method.getModifiers();
Expand Down Expand Up @@ -1118,7 +1117,7 @@ private int writeArrayTypeUnit(DebugContext context, ArrayTypeEntry arrayTypeEnt
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
pos = writeAbbrevCode(abbrevCode, buffer, pos);
log(context, " [0x%08x] language %s", pos, "DwarfDebugInfo.DW_LANG_Java");
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
String name = arrayTypeEntry.getTypeName();
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(name), name);
pos = writeStrSectionOffset(name, buffer, pos);
Expand Down Expand Up @@ -1300,7 +1299,7 @@ private int writeDeoptMethodsCU(DebugContext context, ClassEntry classEntry, byt
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
pos = writeAbbrevCode(abbrevCode, buffer, pos);
log(context, " [0x%08x] language %s", pos, "DwarfDebugInfo.DW_LANG_Java");
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
log(context, " [0x%08x] use_UTF8", pos);
pos = writeFlag((byte) 1, buffer, pos);
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(classEntry.getFileName()), classEntry.getFileName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import jdk.vm.ci.meta.JavaKind;
import org.graalvm.compiler.graph.Node.NodeIntrinsic;
import org.graalvm.compiler.java.LambdaUtils;
import org.graalvm.compiler.nodes.BreakpointNode;
Expand Down Expand Up @@ -300,11 +299,13 @@ public static String uniqueShortName(String loaderNameAndId, ResolvedJavaType de
}

public static String toolFriendlyMangle(ResolvedJavaMethod m) {
/*-
*
if (false) {
return elfMangle(m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
} else {
return bfdMangle(m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
}
*/
return bfdMangle(m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
}

public static String classLoaderNameAndId(ClassLoader loader) {
Expand Down Expand Up @@ -460,13 +461,12 @@ public static String elfMangle(ResolvedJavaType declaringClass, String methodNam
return sb.toString();
}


/**
* mangle a method name in a format the binutils demangler will understand. This should allow
* all Linux tools to translate mangled symbol names to recognisable Java names in the same format
* as derived from the DWARF info, i.e. fully qualified classname using '.' separator, method name
* separated using '::' and parameter/return types printed either using the Java primitive name
* or, for oops, as a pointer to a struct whose name is that of the Java type.
* all Linux tools to translate mangled symbol names to recognisable Java names in the same
* format as derived from the DWARF info, i.e. fully qualified classname using '.' separator,
* method name separated using '::' and parameter/return types printed either using the Java
* primitive name or, for oops, as a pointer to a struct whose name is that of the Java type.
*
* @param declaringClass the class owning the method implementation
* @param methodName the simple name of the method
Expand Down Expand Up @@ -635,10 +635,12 @@ public static String bfdMangle(ResolvedJavaType declaringClass, String methodNam
private static class BFDMangler {
final StringBuilder sb;
final List<String> prefixes;
public BFDMangler() {

BFDMangler() {
sb = new StringBuilder("_Z");
prefixes = new ArrayList<String>();
prefixes = new ArrayList<>();
}

public String mangle(ResolvedJavaType declaringClass, String methodName, Signature methodSignature, boolean isConstructor) {
String fqn = declaringClass.toJavaName();
if (isConstructor) {
Expand All @@ -658,10 +660,12 @@ public String mangle(ResolvedJavaType declaringClass, String methodName, Signatu
mangleParams(methodSignature);
return sb.toString();
}

private void mangleSimpleName(String s) {
sb.append(s.length());
sb.append(s);
}

private void manglePrefix(String prefix) {
int index = prefixIdx(prefix);
if (index >= 0) {
Expand All @@ -671,30 +675,18 @@ private void manglePrefix(String prefix) {
recordPrefix(prefix);
}
}

private void mangleClassAndMethodName(String name, String methodName) {
sb.append('N');
mangleClassName(name, true);
mangleClassName(name);
mangleMethodName(methodName);
sb.append('E');
}
private void mangleClassName(String name, boolean asPrefix) {
/*
* This code generates package elements separately as though they were namespaces
* meaning that we get '::' as the separator
String[] elements = name.split("\\.");
int count = elements.length;
for (int i = 0; i < count - 1; i++) {
manglePrefix(elements[i]);
}
if (asPrefix) {
manglePrefix(elements[count - 1]);
} else {
mangleSimpleName(elements[count - 1]);
}
*/

private void mangleClassName(String name) {
/*
* This code generates the FQN of the class including '.' separators as a prefix
* meaning we only see the '::' separator between class FQN and method name
* This code generates the FQN of the class including '.' separators as a prefix meaning
* we only see the '::' separator between class FQN and method name
*/
manglePrefix(name);
}
Expand All @@ -708,6 +700,7 @@ private void mangleReturnType(Signature methodSignature) {
sb.append('J');
mangleType(type);
}

private void mangleParams(Signature methodSignature) {
int count = methodSignature.getParameterCount(false);
for (int i = 0; i < count; i++) {
Expand All @@ -718,6 +711,7 @@ private void mangleParams(Signature methodSignature) {
mangleTypeChar('V');
}
}

private void mangleType(ResolvedJavaType type) {
if (type.isPrimitive()) {
manglePrimitiveType(type);
Expand All @@ -726,18 +720,11 @@ private void mangleType(ResolvedJavaType type) {
mangleArrayType(type);
} else {
sb.append('P');
mangleClassName(type.toJavaName(), false);
mangleClassName(type.toJavaName());
}
}

private void mangleArrayType(ResolvedJavaType arrayType) {
/*
* This code mangles the type as an Array<T> template
manglePrefix("JArray");
sb.append('I');
mangleType(arrayType.getComponentType());
sb.append('E');
*/
/*
* This code mangles the array name as a symbol using the array base type and required
* number of '[]' pairs.
Expand Down Expand Up @@ -799,7 +786,8 @@ private void mangleTypeChar(char c) {

private void writePrefix(int i) {
sb.append('S');
// i = 0 has no digits, i = 1 -> 0, ... i = 10 -> 9, i = 11 -> A, ... i = 36 -> Z, i = 37 -> 10, ...
// i = 0 has no digits, i = 1 -> 0, ... i = 10 -> 9, i = 11 -> A, ... i = 36 -> Z, i =
// 37 -> 10, ...
// allow for at most up 2 base 36 digits
if (i > 36) {
sb.append(b36((i - 1) / 36));
Expand All @@ -810,13 +798,14 @@ private void writePrefix(int i) {
sb.append('_');
}

private char b36(int i) {
private static char b36(int i) {
if (i < 10) {
return (char)('0' + i);
return (char) ('0' + i);
} else {
return (char)('A' + (i - 10));
return (char) ('A' + (i - 10));
}
}

private void recordPrefix(String prefix) {
prefixes.add(prefix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,17 @@ private void markDataRelocationSiteFromText(RelocatableBuffer buffer, final Prog
* does)
*/
public static String localSymbolNameForMethod(ResolvedJavaMethod sm) {
/* We don't mangle local symbols, because they never need be referenced by an assembler. */
if (OS.LINUX.isCurrent() &&
SubstrateOptions.GenerateDebugInfo.getValue() > 0) {
/*
* We don't normally mangle local symbols, because they do not need to be referenced by an
* assembler. However, on Linux we do mangle them when debug info is enabled. This allows
* them to be used as the linkage name in DWARF info. At the very least this means that: gdb
* is able to demangle them for use in code disassembly listings; and perf is able to use
* them to label method code addresses included in profile samples. However, it also means
* that when local symbols are retained perf, valgrind and any other tools that rely on
* DWARF and bfd demangling are able to label methods correctly and can be asked to report
* details of method code using the standard Java name to identify the desired method.
*/
if (OS.LINUX.isCurrent() && SubstrateOptions.GenerateDebugInfo.getValue() > 0) {
// use tool friendly symbol names
return SubstrateUtil.toolFriendlyMangle(sm);
}
Expand Down

0 comments on commit 47e81a3

Please sign in to comment.