From 348db87f358dc6dc822e6bfa163e17b986fd5d42 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Mon, 13 Dec 2021 16:23:40 +0200 Subject: [PATCH] Refactor: Don't generate 0-sized arrays for methods with no arguments --- .../objectfile/debugentry/ClassEntry.java | 18 +++++++++++------- .../objectfile/debugentry/MethodEntry.java | 4 ++-- .../oracle/objectfile/debugentry/Range.java | 13 ++++++++----- .../elf/dwarf/DwarfInfoSectionImpl.java | 3 +++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java index 643ad61ec936..fc21a324bf03 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/ClassEntry.java @@ -292,14 +292,18 @@ protected MethodEntry processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBa debugContext.log("typename %s adding %s method %s %s(%s)\n", typeName, memberModifiers(modifiers), resultTypeName, methodName, formatParams(paramTypes, paramNames)); TypeEntry resultType = debugInfoBase.lookupTypeEntry(resultTypeName); - TypeEntry[] paramTypeArray = new TypeEntry[paramCount]; - String[] paramNameArray = new String[paramCount]; - int idx = 0; - for (String paramTypeName : paramTypes) { - TypeEntry paramType = debugInfoBase.lookupTypeEntry(TypeEntry.canonicalize(paramTypeName)); - paramTypeArray[idx++] = paramType; + TypeEntry[] paramTypeArray = null; + String[] paramNameArray = null; + if (paramCount != 0) { + paramTypeArray = new TypeEntry[paramCount]; + paramNameArray = new String[paramCount]; + int idx = 0; + for (String paramTypeName : paramTypes) { + TypeEntry paramType = debugInfoBase.lookupTypeEntry(TypeEntry.canonicalize(paramTypeName)); + paramTypeArray[idx++] = paramType; + } + paramNameArray = paramNames.toArray(paramNameArray); } - paramNameArray = paramNames.toArray(paramNameArray); /* * n.b. the method file may differ from the owning class file when the method is a * substitution diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/MethodEntry.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/MethodEntry.java index a5ab87a66717..3f1172b612d0 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/MethodEntry.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/MethodEntry.java @@ -31,8 +31,8 @@ import com.oracle.objectfile.debuginfo.DebugInfoProvider.DebugMethodInfo; public class MethodEntry extends MemberEntry { - final TypeEntry[] paramTypes; - final String[] paramNames; + private final TypeEntry[] paramTypes; + private final String[] paramNames; static final int DEOPT = 1 << 0; static final int IN_RANGE = 1 << 1; static final int INLINED = 1 << 2; diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/Range.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/Range.java index c3f7e5ca594e..71d3674ae61c 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/Range.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/Range.java @@ -182,11 +182,14 @@ private String getExtendedMethodName(boolean includeClass, boolean includeParams builder.append(getMethodName()); if (includeParams) { builder.append("("); - String prefix = ""; - for (TypeEntry t : methodEntry.paramTypes) { - builder.append(prefix); - builder.append(t.getTypeName()); - prefix = ", "; + TypeEntry[] paramTypes = methodEntry.getParamTypes(); + if (paramTypes != null) { + String prefix = ""; + for (TypeEntry t : paramTypes) { + builder.append(prefix); + builder.append(t.getTypeName()); + prefix = ", "; + } } builder.append(')'); } diff --git a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java index 9a93f68fd374..b8341cf197de 100644 --- a/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java +++ b/substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfInfoSectionImpl.java @@ -737,6 +737,9 @@ private int writeMethodParameterDeclarations(DebugContext context, ClassEntry cl if (!Modifier.isStatic(method.getModifiers())) { pos = writeMethodParameterDeclaration(context, "this", classEntry.getTypeName(), true, isSpecification, buffer, pos); } + if (method.getParamTypes() == null) { + return pos; + } for (TypeEntry paramType : method.getParamTypes()) { String paramTypeName = paramType.getTypeName(); String paramName = uniqueDebugString("");