Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2020, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand All @@ -26,7 +26,7 @@

package com.oracle.objectfile.debugentry;

import com.oracle.objectfile.debuginfo.DebugInfoProvider;
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFieldInfo;
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugFrameSizeChange;
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugMethodInfo;
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo;
Expand All @@ -35,9 +35,11 @@
import org.graalvm.compiler.debug.DebugContext;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

/**
Expand All @@ -51,7 +53,7 @@ public class ClassEntry extends StructureTypeEntry {
/**
* Details of this class's interfaces.
*/
protected LinkedList<InterfaceClassEntry> interfaces;
protected List<InterfaceClassEntry> interfaces;
/**
* Details of the associated file.
*/
Expand All @@ -64,7 +66,7 @@ public class ClassEntry extends StructureTypeEntry {
* A list recording details of all primary ranges included in this class sorted by ascending
* address range.
*/
private LinkedList<PrimaryEntry> primaryEntries;
private List<PrimaryEntry> primaryEntries;
/**
* An index identifying primary ranges which have already been encountered.
*/
Expand All @@ -76,30 +78,32 @@ public class ClassEntry extends StructureTypeEntry {
/**
* A list of the same files.
*/
private LinkedList<FileEntry> localFiles;
private List<FileEntry> localFiles;
/**
* An index of all primary and secondary dirs referenced from this class's compilation unit.
*/
private HashMap<DirEntry, Integer> localDirsIndex;
/**
* A list of the same dirs.
*/
private LinkedList<DirEntry> localDirs;
private List<DirEntry> localDirs;
/**
* This flag is true iff the entry includes methods that are deopt targets.
*/
private boolean includesDeoptTarget;

public ClassEntry(String className, FileEntry fileEntry, int size) {
super(className, size);
this.interfaces = new LinkedList<>();
this.interfaces = new ArrayList<>();
this.fileEntry = fileEntry;
// methods is a sorted list and we want to be able to add more elements to it while keeping it sorted,
// so a LinkedList seems more appropriate than an ArrayList. (see getMethodEntry)
this.methods = new LinkedList<>();
this.primaryEntries = new LinkedList<>();
this.primaryEntries = new ArrayList<>();
this.primaryIndex = new HashMap<>();
this.localFiles = new LinkedList<>();
this.localFiles = new ArrayList<>();
this.localFilesIndex = new HashMap<>();
this.localDirs = new LinkedList<>();
this.localDirs = new ArrayList<>();
this.localDirsIndex = new HashMap<>();
if (fileEntry != null) {
localFiles.add(fileEntry);
Expand Down Expand Up @@ -134,7 +138,9 @@ public void addDebugInfo(DebugInfoBase debugInfoBase, DebugTypeInfo debugTypeInf
/* Add details of fields and field types */
debugInstanceTypeInfo.fieldInfoProvider().forEach(debugFieldInfo -> this.processField(debugFieldInfo, debugInfoBase, debugContext));
/* Add details of methods and method types */
debugInstanceTypeInfo.methodInfoProvider().forEach(methodFieldInfo -> this.processMethod(methodFieldInfo, debugInfoBase, debugContext));
debugInstanceTypeInfo.methodInfoProvider().forEach(methodFieldInfo -> this.methods.add(this.processMethod(methodFieldInfo, debugInfoBase, debugContext)));
/* Sort methods to improve lookup speed */
this.methods.sort(MethodEntry::compareTo);
}

public void indexPrimary(Range primary, List<DebugFrameSizeChange> frameSizeInfos, int frameSize) {
Expand Down Expand Up @@ -227,7 +233,7 @@ public FileEntry getFileEntry() {
return fileEntry;
}

public LinkedList<PrimaryEntry> getPrimaryEntries() {
public List<PrimaryEntry> getPrimaryEntries() {
return primaryEntries;
}

Expand All @@ -236,11 +242,11 @@ public Object primaryIndexFor(Range primaryRange) {
return primaryIndex.get(primaryRange);
}

public LinkedList<DirEntry> getLocalDirs() {
public List<DirEntry> getLocalDirs() {
return localDirs;
}

public LinkedList<FileEntry> getLocalFiles() {
public List<FileEntry> getLocalFiles() {
return localFiles;
}

Expand All @@ -267,7 +273,7 @@ private void processInterface(String interfaceName, DebugInfoBase debugInfoBase,
interfaceClassEntry.addImplementor(this, debugContext);
}

protected void processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
String methodName = debugInfoBase.uniqueDebugString(debugMethodInfo.name());
String resultTypeName = TypeEntry.canonicalize(debugMethodInfo.valueType());
int modifiers = debugMethodInfo.modifiers();
Expand All @@ -294,11 +300,11 @@ protected void processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debu
* substitution
*/
FileEntry methodFileEntry = debugInfoBase.ensureFileEntry(fileName, filePath, cachePath);
methods.add(new MethodEntry(methodFileEntry, methodName, this, resultType, paramTypeArray, paramNameArray, modifiers));
return new MethodEntry(methodFileEntry, methodName, this, resultType, paramTypeArray, paramNameArray, modifiers, debugMethodInfo.isDeoptTarget());
}

@Override
protected FieldEntry addField(DebugInfoProvider.DebugFieldInfo debugFieldInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
protected FieldEntry addField(DebugFieldInfo debugFieldInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
FieldEntry fieldEntry = super.addField(debugFieldInfo, debugInfoBase, debugContext);
FileEntry fieldFileEntry = fieldEntry.getFileEntry();
if (fieldFileEntry != null) {
Expand Down Expand Up @@ -335,27 +341,39 @@ public ClassEntry getSuperClass() {
return superClass;
}

public Range makePrimaryRange(String methodName, String symbolName, String paramSignature, String returnTypeName, StringTable stringTable, FileEntry primaryFileEntry, int lo,
int hi, int primaryLine,
int modifiers, boolean isDeoptTarget) {
FileEntry fileEntryToUse = primaryFileEntry;
public Range makePrimaryRange(String symbolName, StringTable stringTable, MethodEntry method, int lo, int hi, int primaryLine) {
FileEntry fileEntryToUse = method.fileEntry;
if (fileEntryToUse == null) {
/*
* Search for a matching method to supply the file entry or failing that use the one
* from this class.
*/
for (MethodEntry methodEntry : methods) {
if (methodEntry.match(methodName, paramSignature, returnTypeName)) {
/* maybe the method's file entry */
fileEntryToUse = methodEntry.getFileEntry();
break;
}
}
if (fileEntryToUse == null) {
/* Last chance is the class's file entry. */
fileEntryToUse = this.fileEntry;
/* Last chance is the class's file entry. */
fileEntryToUse = this.fileEntry;
}
return new Range(symbolName, stringTable, method, fileEntryToUse, lo, hi, primaryLine);
}

public MethodEntry getMethodEntry(DebugMethodInfo debugMethodInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
assert listIsSorted(methods);
String methodName = debugInfoBase.uniqueDebugString(debugMethodInfo.name());
String paramSignature = debugMethodInfo.paramSignature();
String returnTypeName = debugMethodInfo.valueType();
ListIterator<MethodEntry> methodIterator = methods.listIterator();
while (methodIterator.hasNext()) {
MethodEntry methodEntry = methodIterator.next();
int comparisonResult = methodEntry.compareTo(methodName, paramSignature, returnTypeName);
if (comparisonResult == 0) {
return methodEntry;
} else if (comparisonResult > 0) {
methodIterator.previous();
break;
}
}
return new Range(this.typeName, methodName, symbolName, paramSignature, returnTypeName, stringTable, fileEntryToUse, lo, hi, primaryLine, modifiers, isDeoptTarget);
MethodEntry newMethodEntry = processMethod(debugMethodInfo, debugInfoBase, debugContext);
methodIterator.add(newMethodEntry);
return newMethodEntry;
}

private static boolean listIsSorted(List<MethodEntry> list) {
List<MethodEntry> copy = new ArrayList<>(list);
copy.sort(MethodEntry::compareTo);
return list.equals(copy);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2020, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -29,8 +29,9 @@
import java.nio.ByteOrder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.graalvm.compiler.debug.DebugContext;
Expand Down Expand Up @@ -89,15 +90,15 @@ public abstract class DebugInfoBase {
/**
* List of class entries detailing class info for primary ranges.
*/
private LinkedList<TypeEntry> types = new LinkedList<>();
private List<TypeEntry> types = new ArrayList<>();
/**
* index of already seen classes.
*/
private Map<String, TypeEntry> typesIndex = new HashMap<>();
/**
* List of class entries detailing class info for primary ranges.
*/
private LinkedList<ClassEntry> primaryClasses = new LinkedList<>();
private List<ClassEntry> primaryClasses = new ArrayList<>();
/**
* index of already seen classes.
*/
Expand All @@ -109,7 +110,7 @@ public abstract class DebugInfoBase {
/**
* List of of files which contain primary or secondary ranges.
*/
private LinkedList<FileEntry> files = new LinkedList<>();
private List<FileEntry> files = new ArrayList<>();
/**
* Flag set to true if heap references are stored as addresses relative to a heap base register
* otherwise false.
Expand Down Expand Up @@ -236,40 +237,35 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
*/
String fileName = debugCodeInfo.fileName();
Path filePath = debugCodeInfo.filePath();
Path cachePath = debugCodeInfo.cachePath();
String className = TypeEntry.canonicalize(debugCodeInfo.className());
String methodName = debugCodeInfo.methodName();
String className = TypeEntry.canonicalize(debugCodeInfo.ownerType());
String methodName = debugCodeInfo.name();
String symbolName = debugCodeInfo.symbolNameForMethod();
String paramSignature = debugCodeInfo.paramSignature();
String returnTypeName = TypeEntry.canonicalize(debugCodeInfo.returnTypeName());
int lo = debugCodeInfo.addressLo();
int hi = debugCodeInfo.addressHi();
int primaryLine = debugCodeInfo.line();
boolean isDeoptTarget = debugCodeInfo.isDeoptTarget();
int modifiers = debugCodeInfo.getModifiers();

/* Search for a method defining this primary range. */
ClassEntry classEntry = ensureClassEntry(className);
FileEntry fileEntry = ensureFileEntry(fileName, filePath, cachePath);
Range primaryRange = classEntry.makePrimaryRange(methodName, symbolName, paramSignature, returnTypeName, stringTable, fileEntry, lo, hi, primaryLine, modifiers, isDeoptTarget);
MethodEntry methodEntry = classEntry.getMethodEntry(debugCodeInfo, this, debugContext);
Range primaryRange = classEntry.makePrimaryRange(symbolName, stringTable, methodEntry, lo, hi, primaryLine);
debugContext.log(DebugContext.INFO_LEVEL, "PrimaryRange %s.%s %s %s:%d [0x%x, 0x%x]", className, methodName, filePath, fileName, primaryLine, lo, hi);
classEntry.indexPrimary(primaryRange, debugCodeInfo.getFrameSizeChanges(), debugCodeInfo.getFrameSize());
debugCodeInfo.lineInfoProvider().forEach(debugLineInfo -> {
String fileNameAtLine = debugLineInfo.fileName();
Path filePathAtLine = debugLineInfo.filePath();
String classNameAtLine = TypeEntry.canonicalize(debugLineInfo.className());
String methodNameAtLine = debugLineInfo.methodName();
String classNameAtLine = TypeEntry.canonicalize(debugLineInfo.ownerType());
String methodNameAtLine = debugLineInfo.name();
String symbolNameAtLine = debugLineInfo.symbolNameForMethod();
int loAtLine = lo + debugLineInfo.addressLo();
int hiAtLine = lo + debugLineInfo.addressHi();
int line = debugLineInfo.line();
Path cachePathAtLine = debugLineInfo.cachePath();
/*
* Record all subranges even if they have no line or file so we at least get a
* symbol for them and don't see a break in the address range.
*/
FileEntry subFileEntry = ensureFileEntry(fileNameAtLine, filePathAtLine, cachePathAtLine);
Range subRange = new Range(classNameAtLine, methodNameAtLine, symbolNameAtLine, stringTable, subFileEntry, loAtLine, hiAtLine, line, primaryRange);
ClassEntry subClassEntry = ensureClassEntry(classNameAtLine);
MethodEntry subMethodEntry = subClassEntry.getMethodEntry(debugLineInfo, this, debugContext);
Range subRange = new Range(symbolNameAtLine, stringTable, subMethodEntry, loAtLine, hiAtLine, line, primaryRange);
classEntry.indexSubRange(subRange);
try (DebugContext.Scope s = debugContext.scope("Subranges")) {
debugContext.log(DebugContext.VERBOSE_LEVEL, "SubRange %s.%s %s %s:%d 0x%x, 0x%x]", classNameAtLine, methodNameAtLine, filePathAtLine, fileNameAtLine, line, loAtLine, hiAtLine);
Expand Down Expand Up @@ -431,16 +427,16 @@ public ByteOrder getByteOrder() {
return byteOrder;
}

public LinkedList<TypeEntry> getTypes() {
public List<TypeEntry> getTypes() {
return types;
}

public LinkedList<ClassEntry> getPrimaryClasses() {
public List<ClassEntry> getPrimaryClasses() {
return primaryClasses;
}

@SuppressWarnings("unused")
public LinkedList<FileEntry> getFiles() {
public List<FileEntry> getFiles() {
return files;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugTypeInfo.DebugTypeKind;
import org.graalvm.compiler.debug.DebugContext;

import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

Expand All @@ -40,7 +40,7 @@ public class InterfaceClassEntry extends ClassEntry {

public InterfaceClassEntry(String className, FileEntry fileEntry, int size) {
super(className, fileEntry, size);
implementors = new LinkedList<>();
implementors = new ArrayList<>();
}

@Override
Expand Down
Loading