Skip to content

Commit 47e81a3

Browse files
committed
revert language attribute and fix docs/style issues
1 parent de67018 commit 47e81a3

File tree

4 files changed

+50
-51
lines changed

4 files changed

+50
-51
lines changed

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfDebugInfo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ public class DwarfDebugInfo extends DebugInfoBase {
208208
* Value for DW_AT_language attribute with form DATA1.
209209
*/
210210
public static final byte DW_LANG_Java = 0xb;
211-
public static final byte DW_LANG_C_plus_plus = 0x4;
212-
public static final byte SELECTED_LANG_ENCODING = DW_LANG_C_plus_plus;
211+
/**
212+
* This field defines the value used for the DW_AT_language attribute of compile units.
213+
*
214+
*/
215+
public static final byte LANG_ENCODING = DW_LANG_Java;
213216
/*
214217
* Values for {@link DW_AT_inline} attribute with form DATA1.
215218
*/

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private int writeBuiltInUnit(DebugContext context, byte[] buffer, int p) {
198198
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
199199
pos = writeAbbrevCode(abbrevCode, buffer, pos);
200200
log(context, " [0x%08x] language %s", pos, "DW_LANG_Java");
201-
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
201+
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
202202

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

@@ -351,7 +351,7 @@ private int writeNonCompiledClassUnit(DebugContext context, ClassEntry classEntr
351351
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
352352
pos = writeAbbrevCode(abbrevCode, buffer, pos);
353353
log(context, " [0x%08x] language %s", pos, "DW_LANG_Java");
354-
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
354+
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
355355
log(context, " [0x%08x] use_UTF8", pos);
356356
pos = writeFlag((byte) 1, buffer, pos);
357357
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(classEntry.getFileName()), classEntry.getFileName());
@@ -420,7 +420,7 @@ private int writeCompiledClassUnit(DebugContext context, ClassEntry classEntry,
420420
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
421421
pos = writeAbbrevCode(abbrevCode, buffer, pos);
422422
log(context, " [0x%08x] language %s", pos, "DW_LANG_Java");
423-
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
423+
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
424424
log(context, " [0x%08x] use_UTF8", pos);
425425
pos = writeFlag((byte) 1, buffer, pos);
426426
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(fileName), fileName);
@@ -658,7 +658,6 @@ private int writeMethodDeclarations(DebugContext context, ClassEntry classEntry,
658658
private int writeMethodDeclaration(DebugContext context, ClassEntry classEntry, MethodEntry method, byte[] buffer, int p) {
659659
int pos = p;
660660
String methodKey = method.getSymbolName();
661-
// String linkageName = uniqueDebugString(classEntry.getTypeName() + "::" + method.methodName());
662661
String linkageName = uniqueDebugString(methodKey);
663662
setMethodDeclarationIndex(method, pos);
664663
int modifiers = method.getModifiers();
@@ -1118,7 +1117,7 @@ private int writeArrayTypeUnit(DebugContext context, ArrayTypeEntry arrayTypeEnt
11181117
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
11191118
pos = writeAbbrevCode(abbrevCode, buffer, pos);
11201119
log(context, " [0x%08x] language %s", pos, "DwarfDebugInfo.DW_LANG_Java");
1121-
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
1120+
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
11221121
String name = arrayTypeEntry.getTypeName();
11231122
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(name), name);
11241123
pos = writeStrSectionOffset(name, buffer, pos);
@@ -1300,7 +1299,7 @@ private int writeDeoptMethodsCU(DebugContext context, ClassEntry classEntry, byt
13001299
log(context, " [0x%08x] <0> Abbrev Number %d", pos, abbrevCode);
13011300
pos = writeAbbrevCode(abbrevCode, buffer, pos);
13021301
log(context, " [0x%08x] language %s", pos, "DwarfDebugInfo.DW_LANG_Java");
1303-
pos = writeAttrData1(DwarfDebugInfo.SELECTED_LANG_ENCODING, buffer, pos);
1302+
pos = writeAttrData1(DwarfDebugInfo.LANG_ENCODING, buffer, pos);
13041303
log(context, " [0x%08x] use_UTF8", pos);
13051304
pos = writeFlag((byte) 1, buffer, pos);
13061305
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(classEntry.getFileName()), classEntry.getFileName());

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

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.util.regex.Matcher;
3838
import java.util.regex.Pattern;
3939

40-
import jdk.vm.ci.meta.JavaKind;
4140
import org.graalvm.compiler.graph.Node.NodeIntrinsic;
4241
import org.graalvm.compiler.java.LambdaUtils;
4342
import org.graalvm.compiler.nodes.BreakpointNode;
@@ -300,11 +299,13 @@ public static String uniqueShortName(String loaderNameAndId, ResolvedJavaType de
300299
}
301300

302301
public static String toolFriendlyMangle(ResolvedJavaMethod m) {
302+
/*-
303+
*
303304
if (false) {
304305
return elfMangle(m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
305-
} else {
306-
return bfdMangle(m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
307306
}
307+
*/
308+
return bfdMangle(m.getDeclaringClass(), m.getName(), m.getSignature(), m.isConstructor());
308309
}
309310

310311
public static String classLoaderNameAndId(ClassLoader loader) {
@@ -460,13 +461,12 @@ public static String elfMangle(ResolvedJavaType declaringClass, String methodNam
460461
return sb.toString();
461462
}
462463

463-
464464
/**
465465
* mangle a method name in a format the binutils demangler will understand. This should allow
466-
* all Linux tools to translate mangled symbol names to recognisable Java names in the same format
467-
* as derived from the DWARF info, i.e. fully qualified classname using '.' separator, method name
468-
* separated using '::' and parameter/return types printed either using the Java primitive name
469-
* or, for oops, as a pointer to a struct whose name is that of the Java type.
466+
* all Linux tools to translate mangled symbol names to recognisable Java names in the same
467+
* format as derived from the DWARF info, i.e. fully qualified classname using '.' separator,
468+
* method name separated using '::' and parameter/return types printed either using the Java
469+
* primitive name or, for oops, as a pointer to a struct whose name is that of the Java type.
470470
*
471471
* @param declaringClass the class owning the method implementation
472472
* @param methodName the simple name of the method
@@ -635,10 +635,12 @@ public static String bfdMangle(ResolvedJavaType declaringClass, String methodNam
635635
private static class BFDMangler {
636636
final StringBuilder sb;
637637
final List<String> prefixes;
638-
public BFDMangler() {
638+
639+
BFDMangler() {
639640
sb = new StringBuilder("_Z");
640-
prefixes = new ArrayList<String>();
641+
prefixes = new ArrayList<>();
641642
}
643+
642644
public String mangle(ResolvedJavaType declaringClass, String methodName, Signature methodSignature, boolean isConstructor) {
643645
String fqn = declaringClass.toJavaName();
644646
if (isConstructor) {
@@ -658,10 +660,12 @@ public String mangle(ResolvedJavaType declaringClass, String methodName, Signatu
658660
mangleParams(methodSignature);
659661
return sb.toString();
660662
}
663+
661664
private void mangleSimpleName(String s) {
662665
sb.append(s.length());
663666
sb.append(s);
664667
}
668+
665669
private void manglePrefix(String prefix) {
666670
int index = prefixIdx(prefix);
667671
if (index >= 0) {
@@ -671,30 +675,18 @@ private void manglePrefix(String prefix) {
671675
recordPrefix(prefix);
672676
}
673677
}
678+
674679
private void mangleClassAndMethodName(String name, String methodName) {
675680
sb.append('N');
676-
mangleClassName(name, true);
681+
mangleClassName(name);
677682
mangleMethodName(methodName);
678683
sb.append('E');
679684
}
680-
private void mangleClassName(String name, boolean asPrefix) {
681-
/*
682-
* This code generates package elements separately as though they were namespaces
683-
* meaning that we get '::' as the separator
684-
String[] elements = name.split("\\.");
685-
int count = elements.length;
686-
for (int i = 0; i < count - 1; i++) {
687-
manglePrefix(elements[i]);
688-
}
689-
if (asPrefix) {
690-
manglePrefix(elements[count - 1]);
691-
} else {
692-
mangleSimpleName(elements[count - 1]);
693-
}
694-
*/
685+
686+
private void mangleClassName(String name) {
695687
/*
696-
* This code generates the FQN of the class including '.' separators as a prefix
697-
* meaning we only see the '::' separator between class FQN and method name
688+
* This code generates the FQN of the class including '.' separators as a prefix meaning
689+
* we only see the '::' separator between class FQN and method name
698690
*/
699691
manglePrefix(name);
700692
}
@@ -708,6 +700,7 @@ private void mangleReturnType(Signature methodSignature) {
708700
sb.append('J');
709701
mangleType(type);
710702
}
703+
711704
private void mangleParams(Signature methodSignature) {
712705
int count = methodSignature.getParameterCount(false);
713706
for (int i = 0; i < count; i++) {
@@ -718,6 +711,7 @@ private void mangleParams(Signature methodSignature) {
718711
mangleTypeChar('V');
719712
}
720713
}
714+
721715
private void mangleType(ResolvedJavaType type) {
722716
if (type.isPrimitive()) {
723717
manglePrimitiveType(type);
@@ -726,18 +720,11 @@ private void mangleType(ResolvedJavaType type) {
726720
mangleArrayType(type);
727721
} else {
728722
sb.append('P');
729-
mangleClassName(type.toJavaName(), false);
723+
mangleClassName(type.toJavaName());
730724
}
731725
}
732726

733727
private void mangleArrayType(ResolvedJavaType arrayType) {
734-
/*
735-
* This code mangles the type as an Array<T> template
736-
manglePrefix("JArray");
737-
sb.append('I');
738-
mangleType(arrayType.getComponentType());
739-
sb.append('E');
740-
*/
741728
/*
742729
* This code mangles the array name as a symbol using the array base type and required
743730
* number of '[]' pairs.
@@ -799,7 +786,8 @@ private void mangleTypeChar(char c) {
799786

800787
private void writePrefix(int i) {
801788
sb.append('S');
802-
// i = 0 has no digits, i = 1 -> 0, ... i = 10 -> 9, i = 11 -> A, ... i = 36 -> Z, i = 37 -> 10, ...
789+
// i = 0 has no digits, i = 1 -> 0, ... i = 10 -> 9, i = 11 -> A, ... i = 36 -> Z, i =
790+
// 37 -> 10, ...
803791
// allow for at most up 2 base 36 digits
804792
if (i > 36) {
805793
sb.append(b36((i - 1) / 36));
@@ -810,13 +798,14 @@ private void writePrefix(int i) {
810798
sb.append('_');
811799
}
812800

813-
private char b36(int i) {
801+
private static char b36(int i) {
814802
if (i < 10) {
815-
return (char)('0' + i);
803+
return (char) ('0' + i);
816804
} else {
817-
return (char)('A' + (i - 10));
805+
return (char) ('A' + (i - 10));
818806
}
819807
}
808+
820809
private void recordPrefix(String prefix) {
821810
prefixes.add(prefix);
822811
}

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

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

0 commit comments

Comments
 (0)