Skip to content

Commit 14dff63

Browse files
committed
Use enums for DWARF constants instead of interfaces
1 parent f0d9c88 commit 14dff63

26 files changed

+1285
-970
lines changed

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Map;
3030

3131
import com.oracle.objectfile.debugentry.ClassEntry;
32-
import com.oracle.objectfile.elf.dwarf.constants.DwarfSectionNames;
3332
import org.graalvm.compiler.debug.DebugContext;
3433

3534
import com.oracle.objectfile.LayoutDecision;
@@ -38,6 +37,11 @@
3837
import com.oracle.objectfile.debugentry.CompiledMethodEntry;
3938
import com.oracle.objectfile.debugentry.range.Range;
4039

40+
import static com.oracle.objectfile.elf.dwarf.constants.DwarfSectionName.DW_ARANGES_SECTION;
41+
import static com.oracle.objectfile.elf.dwarf.constants.DwarfSectionName.DW_FRAME_SECTION;
42+
43+
import static com.oracle.objectfile.elf.dwarf.constants.DwarfVersion.DW_VERSION_2;
44+
4145
/**
4246
* Section generator for debug_aranges section.
4347
*/
@@ -47,12 +51,7 @@ public class DwarfARangesSectionImpl extends DwarfSectionImpl {
4751
private static final int AR_HEADER_PAD_SIZE = 4;
4852

4953
public DwarfARangesSectionImpl(DwarfDebugInfo dwarfSections) {
50-
super(dwarfSections);
51-
}
52-
53-
@Override
54-
public String getSectionName() {
55-
return DwarfSectionNames.DW_ARANGES_SECTION_NAME;
54+
super(dwarfSections, DW_ARANGES_SECTION, DW_FRAME_SECTION);
5655
}
5756

5857
@Override
@@ -162,7 +161,7 @@ private int writeHeader(int cuIndex, byte[] buffer, int p) {
162161
// write dummy length for now
163162
pos = writeInt(0, buffer, pos);
164163
/* DWARF version is always 2. */
165-
pos = writeShort(DW_VERSION_2, buffer, pos);
164+
pos = writeDwarfVersion(DW_VERSION_2, buffer, pos);
166165
pos = writeInfoSectionOffset(cuIndex, buffer, pos);
167166
/* Address size is always 8. */
168167
pos = writeByte((byte) 8, buffer, pos);
@@ -186,24 +185,4 @@ int writeARange(DebugContext context, CompiledMethodEntry compiledMethod, byte[]
186185
pos = writeLong(primary.getHi() - primary.getLo(), buffer, pos);
187186
return pos;
188187
}
189-
190-
/*
191-
* The debug_aranges section depends on debug_frame section.
192-
*/
193-
private static final String TARGET_SECTION_NAME = DwarfSectionNames.DW_FRAME_SECTION_NAME;
194-
195-
@Override
196-
public String targetSectionName() {
197-
return TARGET_SECTION_NAME;
198-
}
199-
200-
private final LayoutDecision.Kind[] targetSectionKinds = {
201-
LayoutDecision.Kind.CONTENT,
202-
LayoutDecision.Kind.SIZE
203-
};
204-
205-
@Override
206-
public LayoutDecision.Kind[] targetSectionKinds() {
207-
return targetSectionKinds;
208-
}
209188
}

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

Lines changed: 422 additions & 376 deletions
Large diffs are not rendered by default.

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@
3737
import com.oracle.objectfile.debugentry.TypeEntry;
3838
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugLocalInfo;
3939
import com.oracle.objectfile.elf.ELFMachine;
40-
import com.oracle.objectfile.elf.dwarf.constants.DwarfAttributeValues;
41-
import com.oracle.objectfile.elf.dwarf.constants.DwarfConstants;
40+
import com.oracle.objectfile.elf.dwarf.constants.DwarfLanguage;
4241
import org.graalvm.collections.EconomicMap;
4342

4443
/**
4544
* A class that models the debug info in an organization that facilitates generation of the required
4645
* DWARF sections. It groups common data and behaviours for use by the various subclasses of class
4746
* DwarfSectionImpl that take responsibility for generating content for a specific section type.
4847
*/
49-
public class DwarfDebugInfo extends DebugInfoBase implements DwarfConstants {
48+
public class DwarfDebugInfo extends DebugInfoBase {
5049

5150
public static final String HEAP_BEGIN_NAME = "__svm_heap_begin";
5251

@@ -113,7 +112,7 @@ enum AbbrevCode {
113112
* This field defines the value used for the DW_AT_language attribute of compile units.
114113
*
115114
*/
116-
public static final byte LANG_ENCODING = DwarfAttributeValues.DW_LANG_Java;
115+
public static final DwarfLanguage LANG_ENCODING = DwarfLanguage.DW_LANG_Java;
117116

118117
/* Register constants for AArch64. */
119118
public static final byte rheapbase_aarch64 = (byte) 27;

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

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626

2727
package com.oracle.objectfile.elf.dwarf;
2828

29-
import com.oracle.objectfile.LayoutDecision;
3029
import com.oracle.objectfile.debugentry.CompiledMethodEntry;
3130
import com.oracle.objectfile.debugentry.range.Range;
3231
import com.oracle.objectfile.debuginfo.DebugInfoProvider;
33-
import com.oracle.objectfile.elf.dwarf.constants.DwarfFrameValues;
34-
import com.oracle.objectfile.elf.dwarf.constants.DwarfSectionNames;
32+
import com.oracle.objectfile.elf.dwarf.constants.DwarfFrameValue;
3533
import org.graalvm.compiler.debug.DebugContext;
3634

3735
import java.util.List;
3836

37+
import static com.oracle.objectfile.elf.dwarf.constants.DwarfSectionName.DW_FRAME_SECTION;
38+
import static com.oracle.objectfile.elf.dwarf.constants.DwarfSectionName.DW_LINE_SECTION;
39+
3940
/**
4041
* Section generic generator for debug_frame section.
4142
*/
@@ -46,12 +47,8 @@ public abstract class DwarfFrameSectionImpl extends DwarfSectionImpl {
4647
private static final int CFA_CIE_id_default = -1;
4748

4849
public DwarfFrameSectionImpl(DwarfDebugInfo dwarfSections) {
49-
super(dwarfSections);
50-
}
51-
52-
@Override
53-
public String getSectionName() {
54-
return DwarfSectionNames.DW_FRAME_SECTION_NAME;
50+
// debug_frame section depends on debug_line section
51+
super(dwarfSections, DW_FRAME_SECTION, DW_LINE_SECTION);
5552
}
5653

5754
@Override
@@ -124,7 +121,7 @@ private int writeCIE(byte[] buffer, int p) {
124121
int lengthPos = pos;
125122
pos = writeInt(0, buffer, pos);
126123
pos = writeInt(CFA_CIE_id_default, buffer, pos);
127-
pos = writeByte(DwarfFrameValues.DW_CFA_CIE_version, buffer, pos);
124+
pos = writeCIEVersion(buffer, pos);
128125
pos = writeByte((byte) 0, buffer, pos);
129126
pos = writeULEB(1, buffer, pos);
130127
pos = writeSLEB(-8, buffer, pos);
@@ -141,6 +138,10 @@ private int writeCIE(byte[] buffer, int p) {
141138
return pos;
142139
}
143140

141+
private int writeCIEVersion(byte[] buffer, int pos) {
142+
return writeByte(DwarfFrameValue.DW_CFA_CIE_version.value(), buffer, pos);
143+
}
144+
144145
private int writeMethodFrame(CompiledMethodEntry compiledEntry, byte[] buffer, int p) {
145146
int pos = p;
146147
int lengthPos = pos;
@@ -198,21 +199,22 @@ private int writeFDEHeader(int lo, int hi, byte[] buffer, int p) {
198199
private int writePaddingNops(byte[] buffer, int p) {
199200
int pos = p;
200201
while ((pos & (PADDING_NOPS_ALIGNMENT - 1)) != 0) {
201-
pos = writeByte(DwarfFrameValues.DW_CFA_nop, buffer, pos);
202+
pos = writeByte(DwarfFrameValue.DW_CFA_nop.value(), buffer, pos);
202203
}
203204
return pos;
204205
}
205206

206207
protected int writeDefCFA(int register, int offset, byte[] buffer, int p) {
207208
int pos = p;
208-
pos = writeByte(DwarfFrameValues.DW_CFA_def_cfa, buffer, pos);
209+
pos = writeByte(DwarfFrameValue.DW_CFA_def_cfa.value(), buffer, pos);
209210
pos = writeULEB(register, buffer, pos);
210211
return writeULEB(offset, buffer, pos);
211212
}
212213

213214
protected int writeDefCFAOffset(int offset, byte[] buffer, int p) {
214215
int pos = p;
215-
pos = writeByte(DwarfFrameValues.DW_CFA_def_cfa_offset, buffer, pos);
216+
byte op = DwarfFrameValue.DW_CFA_def_cfa_offset.value();
217+
pos = writeByte(op, buffer, pos);
216218
return writeULEB(offset, buffer, pos);
217219
}
218220

@@ -235,20 +237,20 @@ protected int writeAdvanceLoc0(byte offset, byte[] buffer, int pos) {
235237

236238
protected int writeAdvanceLoc1(byte offset, byte[] buffer, int p) {
237239
int pos = p;
238-
byte op = DwarfFrameValues.DW_CFA_advance_loc1;
240+
byte op = DwarfFrameValue.DW_CFA_advance_loc1.value();
239241
pos = writeByte(op, buffer, pos);
240242
return writeByte(offset, buffer, pos);
241243
}
242244

243245
protected int writeAdvanceLoc2(short offset, byte[] buffer, int p) {
244-
byte op = DwarfFrameValues.DW_CFA_advance_loc2;
246+
byte op = DwarfFrameValue.DW_CFA_advance_loc2.value();
245247
int pos = p;
246248
pos = writeByte(op, buffer, pos);
247249
return writeShort(offset, buffer, pos);
248250
}
249251

250252
protected int writeAdvanceLoc4(int offset, byte[] buffer, int p) {
251-
byte op = DwarfFrameValues.DW_CFA_advance_loc4;
253+
byte op = DwarfFrameValue.DW_CFA_advance_loc4.value();
252254
int pos = p;
253255
pos = writeByte(op, buffer, pos);
254256
return writeInt(offset, buffer, pos);
@@ -270,7 +272,8 @@ protected int writeRestore(int register, byte[] buffer, int p) {
270272
@SuppressWarnings("unused")
271273
protected int writeRegister(int savedReg, int savedToReg, byte[] buffer, int p) {
272274
int pos = p;
273-
pos = writeByte(DwarfFrameValues.DW_CFA_register, buffer, pos);
275+
byte op = DwarfFrameValue.DW_CFA_register.value();
276+
pos = writeByte(op, buffer, pos);
274277
pos = writeULEB(savedReg, buffer, pos);
275278
return writeULEB(savedToReg, buffer, pos);
276279
}
@@ -282,38 +285,23 @@ protected int writeRegister(int savedReg, int savedToReg, byte[] buffer, int p)
282285

283286
protected abstract int writeInitialInstructions(byte[] buffer, int pos);
284287

285-
/**
286-
* The debug_frame section depends on debug_line section.
287-
*/
288-
private static final String TARGET_SECTION_NAME = DwarfSectionNames.DW_LINE_SECTION_NAME;
289-
290-
@Override
291-
public String targetSectionName() {
292-
return TARGET_SECTION_NAME;
293-
}
294-
295-
private final LayoutDecision.Kind[] targetSectionKinds = {
296-
LayoutDecision.Kind.CONTENT,
297-
LayoutDecision.Kind.SIZE
298-
};
299-
300-
@Override
301-
public LayoutDecision.Kind[] targetSectionKinds() {
302-
return targetSectionKinds;
303-
}
304-
305288
private static byte offsetOp(int register) {
306-
assert (register >> 6) == 0;
307-
return (byte) ((DwarfFrameValues.DW_CFA_offset << 6) | register);
289+
byte op = DwarfFrameValue.DW_CFA_offset.value();
290+
return encodeOp(op, register);
308291
}
309292

310293
private static byte restoreOp(int register) {
311-
assert (register >> 6) == 0;
312-
return (byte) ((DwarfFrameValues.DW_CFA_restore << 6) | register);
294+
byte op = DwarfFrameValue.DW_CFA_restore.value();
295+
return encodeOp(op, register);
313296
}
314297

315298
private static byte advanceLoc0Op(int offset) {
316-
assert (offset >= 0 && offset <= 0x3f);
317-
return (byte) ((DwarfFrameValues.DW_CFA_advance_loc << 6) | offset);
299+
byte op = DwarfFrameValue.DW_CFA_advance_loc.value();
300+
return encodeOp(op, offset);
301+
}
302+
303+
private static byte encodeOp(byte op, int value) {
304+
assert (value >> 6) == 0;
305+
return (byte) ((op << 6) | value);
318306
}
319307
}

0 commit comments

Comments
 (0)