From 61869694ef89d63af0192ddadd0202686e7f9b80 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 12 Jun 2020 14:13:40 +0200 Subject: [PATCH] Address some perf issues reported by PMD 2.2: Redundant Field Initializer 52 Avoid Instantiating Objects In Loops 15 Consecutive Appends Should Reuse 14 Inefficient String Buffering 8 Use String Buffer For String Appends 7 Optimizable To Array Call 6 Append Character With Char 5 Insufficient String Buffer Declaration 3 Inefficient Empty String Check 3 Add Empty String 2 Avoid File Stream 1 Use Index Of Char 1 Simplify Starts With 1 --- .../launcher/TruffleSqueakLauncher.java | 18 +-- .../shared/LogHandlerAccessor.java | 7 +- .../test/AbstractSqueakTestCaseWithImage.java | 24 ++-- .../trufflesqueak/test/SqueakSUnitTest.java | 5 +- .../aot/SqueakDisplaySubstitutions.java | 10 +- .../image/SqueakImageContext.java | 26 ++-- .../trufflesqueak/image/SqueakImageFlags.java | 2 +- .../image/SqueakImageReader.java | 4 +- .../interop/JavaObjectWrapper.java | 2 +- .../swa/trufflesqueak/io/SqueakDisplay.java | 35 ++--- .../swa/trufflesqueak/model/ClassObject.java | 4 +- .../model/CompiledCodeObject.java | 2 +- .../model/CompiledMethodObject.java | 13 +- .../trufflesqueak/model/ContextObject.java | 4 +- .../swa/trufflesqueak/model/FloatObject.java | 2 +- .../model/WeakVariablePointersObject.java | 12 +- .../nodes/DispatchEagerlyFromStackNode.java | 4 +- .../nodes/DispatchEagerlyNode.java | 19 +-- .../nodes/plugins/JPEGReader.java | 2 +- .../nodes/plugins/SqueakFFIPrims.java | 11 +- .../nodes/plugins/SqueakSSL.java | 5 +- .../swa/trufflesqueak/nodes/plugins/Zip.java | 12 +- .../nodes/plugins/network/Resolver.java | 4 +- .../primitives/PrimitiveNodeFactory.java | 2 +- .../primitives/impl/ContextPrimitives.java | 2 +- .../tools/SqueakMessageInterceptor.java | 2 +- .../swa/trufflesqueak/util/ArrayUtils.java | 2 +- .../swa/trufflesqueak/util/DebugUtils.java | 127 +++++------------- .../util/InterruptHandlerState.java | 8 +- .../hpi/swa/trufflesqueak/util/MiscUtils.java | 11 +- .../util/SqueakBytecodeDecoder.java | 12 +- 31 files changed, 152 insertions(+), 241 deletions(-) diff --git a/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java b/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java index a1c5c643c..a79f431a0 100644 --- a/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java +++ b/src/de.hpi.swa.trufflesqueak.launcher/src/de/hpi/swa/trufflesqueak/launcher/TruffleSqueakLauncher.java @@ -30,14 +30,14 @@ import de.hpi.swa.trufflesqueak.shared.SqueakLanguageOptions; public final class TruffleSqueakLauncher extends AbstractLanguageLauncher { - private boolean headless = false; - private boolean printImagePath = false; - private boolean quiet = false; + private boolean headless; + private boolean printImagePath; + private boolean quiet; private String[] imageArguments = new String[0]; - private String imagePath = null; - private String sourceCode = null; - private boolean enableTranscriptForwarding = false; - private String logHandlerMode = null; + private String imagePath; + private String sourceCode; + private boolean enableTranscriptForwarding; + private String logHandlerMode; public static void main(final String[] arguments) throws RuntimeException { new TruffleSqueakLauncher().launch(arguments); @@ -51,7 +51,7 @@ protected List preprocessArguments(final List arguments, final M if (isExistingImageFile(arg)) { imagePath = Paths.get(arg).toAbsolutePath().toString(); final List remainingArguments = arguments.subList(i + 1, arguments.size()); - imageArguments = remainingArguments.toArray(new String[remainingArguments.size()]); + imageArguments = remainingArguments.toArray(new String[0]); break; } else if (SqueakLanguageOptions.CODE_FLAG.equals(arg) || SqueakLanguageOptions.CODE_FLAG_SHORT.equals(arg)) { sourceCode = arguments.get(++i); @@ -128,7 +128,7 @@ protected int execute(final Context.Builder contextBuilder) { } catch (final IllegalArgumentException e) { if (e.getMessage().contains("Could not find option with name " + SqueakLanguageConfig.ID)) { final String thisPackageName = getClass().getPackage().getName(); - final String parentPackageName = thisPackageName.substring(0, thisPackageName.lastIndexOf(".")); + final String parentPackageName = thisPackageName.substring(0, thisPackageName.lastIndexOf('.')); throw abort(String.format("Failed to load TruffleSqueak. Please ensure '%s' is on the Java class path.", parentPackageName)); } else { throw e; diff --git a/src/de.hpi.swa.trufflesqueak.shared/src/de/hpi/swa/trufflesqueak/shared/LogHandlerAccessor.java b/src/de.hpi.swa.trufflesqueak.shared/src/de/hpi/swa/trufflesqueak/shared/LogHandlerAccessor.java index 37480f1a3..8469bb76e 100644 --- a/src/de.hpi.swa.trufflesqueak.shared/src/de/hpi/swa/trufflesqueak/shared/LogHandlerAccessor.java +++ b/src/de.hpi.swa.trufflesqueak.shared/src/de/hpi/swa/trufflesqueak/shared/LogHandlerAccessor.java @@ -40,7 +40,6 @@ public final class LogHandlerAccessor { private static boolean firstTime = true; public static Handler createLogHandler(final String mode) { - PrintStream output = null; switch (mode) { case "mapped": if (firstTime) { @@ -59,16 +58,14 @@ public static Handler createLogHandler(final String mode) { firstTime = false; println("TruffleSqueak log handler logging to standard err"); } - output = System.err; - break; + return new StandardPrintStreamHandler(System.err); default: if (firstTime) { firstTime = false; println("TruffleSqueak log handler logging to standard out"); } - output = System.out; + return new StandardPrintStreamHandler(System.out); } - return new StandardPrintStreamHandler(output); } protected static Path getLogPath() { diff --git a/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java b/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java index c6c68de75..daa44579a 100644 --- a/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java +++ b/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/AbstractSqueakTestCaseWithImage.java @@ -9,6 +9,8 @@ import java.io.File; import java.io.FileFilter; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -126,13 +128,13 @@ private static String getPathToTestImage() { } private static String getPathToTestImage(final String imageName) { - File currentDirectory = new File(System.getProperty("user.dir")); + Path currentDirectory = Paths.get(System.getProperty("user.dir")).toAbsolutePath(); while (currentDirectory != null) { - final String pathToImage = currentDirectory.getAbsolutePath() + File.separator + "images" + File.separator + imageName; - if (new File(pathToImage).exists()) { - return pathToImage; + final File file = currentDirectory.resolve("images").resolve(imageName).toFile(); + if (file.exists()) { + return file.getAbsolutePath(); } - currentDirectory = currentDirectory.getParentFile(); + currentDirectory = currentDirectory.getParent(); } return null; } @@ -274,17 +276,17 @@ private static String[] truffleSqueakTestCaseNames() { testCaseNames.add(classDirectories.getName().substring(0, classDirectories.getName().lastIndexOf(".class"))); } } - return testCaseNames.toArray(new String[testCaseNames.size()]); + return testCaseNames.toArray(new String[0]); } protected static final String getPathToInImageCode() { - File currentDirectory = new File(System.getProperty("user.dir")); + Path currentDirectory = Paths.get(System.getProperty("user.dir")).toAbsolutePath(); while (currentDirectory != null) { - final String pathToImage = currentDirectory.getAbsolutePath() + File.separator + "src" + File.separator + "image" + File.separator + "src"; - if (new File(pathToImage).isDirectory()) { - return pathToImage; + final File file = currentDirectory.resolve("src").resolve("image").resolve("src").toFile(); + if (file.isDirectory()) { + return file.getAbsolutePath(); } - currentDirectory = currentDirectory.getParentFile(); + currentDirectory = currentDirectory.getParent(); } return null; } diff --git a/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/SqueakSUnitTest.java b/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/SqueakSUnitTest.java index 03e76cfe1..70ecf0a01 100644 --- a/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/SqueakSUnitTest.java +++ b/src/de.hpi.swa.trufflesqueak.test/src/de/hpi/swa/trufflesqueak/test/SqueakSUnitTest.java @@ -27,6 +27,7 @@ import de.hpi.swa.trufflesqueak.test.SqueakTests.SqueakTest; import de.hpi.swa.trufflesqueak.test.SqueakTests.TestType; +import de.hpi.swa.trufflesqueak.util.MiscUtils; /** * Run tests from the Squeak image. @@ -66,7 +67,7 @@ public class SqueakSUnitTest extends AbstractSqueakTestCaseWithImage { @Parameter public SqueakTest test; - private static boolean truffleSqueakPackagesLoaded = false; + private static boolean truffleSqueakPackagesLoaded; private static boolean stopRunningSuite; @Parameters(name = "{0} (#{index})") @@ -76,7 +77,7 @@ public static Collection getParameters() { private static Stream selectTestsToRun() { final String toRun = System.getProperty(TEST_CLASS_PROPERTY); - if (toRun != null && !toRun.trim().isEmpty()) { + if (toRun != null && !MiscUtils.isBlank(toRun)) { return SqueakTests.getTestsToRun(toRun); } return SqueakTests.allTests(); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakDisplaySubstitutions.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakDisplaySubstitutions.java index afd507b58..281a37363 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakDisplaySubstitutions.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/aot/SqueakDisplaySubstitutions.java @@ -67,17 +67,17 @@ final class Target_de_hpi_swa_trufflesqueak_io_SqueakDisplay implements SqueakDi private Cursor cursor = WordFactory.nullPointer(); private NativeObject bitmap; @CompilationFinal private int inputSemaphoreIndex; - private boolean deferUpdates = false; - private boolean textureDirty = false; + private boolean deferUpdates; + private boolean textureDirty; private int width; private int height; private int bpp = 4; // TODO: for 32bit only! private int lastMouseXPos; private int lastMouseYPos; - private int button = 0; - private int key = 0; - private boolean isKeyDown = false; + private int button; + private int key; + private boolean isKeyDown; Target_de_hpi_swa_trufflesqueak_io_SqueakDisplay(final SqueakImageContext image) { this.image = image; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java index 427fcdd67..b48b9ccee 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageContext.java @@ -95,9 +95,9 @@ public final class SqueakImageContext { public final NativeObject runWithInSelector = new NativeObject(this); public final ArrayObject primitiveErrorTable = new ArrayObject(this); public final ArrayObject specialSelectors = new ArrayObject(this); - @CompilationFinal private ClassObject smallFloatClass = null; - @CompilationFinal private ClassObject byteSymbolClass = null; - @CompilationFinal private ClassObject foreignObjectClass = null; + @CompilationFinal private ClassObject smallFloatClass; + @CompilationFinal private ClassObject byteSymbolClass; + @CompilationFinal private ClassObject foreignObjectClass; public final ArrayObject specialObjectsArray = new ArrayObject(this); public final ClassObject metaClass = new ClassObject(this); @@ -134,14 +134,14 @@ public final class SqueakImageContext { @CompilationFinal private SqueakImage squeakImage; /* Stack Management */ - public int stackDepth = 0; + public int stackDepth; public ContextObject lastSeenContext; - @CompilationFinal private ClassObject compilerClass = null; - @CompilationFinal private ClassObject parserClass = null; - private PointersObject parserSharedInstance = null; - @CompilationFinal private PointersObject scheduler = null; - @CompilationFinal private ClassObject wideStringClass = null; + @CompilationFinal private ClassObject compilerClass; + @CompilationFinal private ClassObject parserClass; + private PointersObject parserSharedInstance; + @CompilationFinal private PointersObject scheduler; + @CompilationFinal private ClassObject wideStringClass; /* Plugins */ public final B2D b2d = new B2D(this); @@ -152,9 +152,9 @@ public final class SqueakImageContext { /* Error detection for headless execution */ @CompilationFinal(dimensions = 1) public static final byte[] DEBUG_ERROR_SELECTOR_NAME = "debugError:".getBytes(); - @CompilationFinal private NativeObject debugErrorSelector = null; + @CompilationFinal private NativeObject debugErrorSelector; @CompilationFinal(dimensions = 1) public static final byte[] DEBUG_SYNTAX_ERROR_SELECTOR_NAME = "debugSyntaxError:".getBytes(); - @CompilationFinal private NativeObject debugSyntaxErrorSelector = null; + @CompilationFinal private NativeObject debugSyntaxErrorSelector; public SqueakImageContext(final SqueakLanguage squeakLanguage, final SqueakLanguage.Env environment) { language = squeakLanguage; @@ -517,9 +517,9 @@ public void setImagePath(final String path) { public String getImageDirectory() { final Path parent = Paths.get(getImagePath()).getParent(); if (parent != null) { - return "" + parent.getFileName(); // Avoids NullPointerExceptions. + return parent.toString(); } else { - throw SqueakException.create("`parent` should not be `null`."); + throw SqueakException.create("Could not determine image directory."); } } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java index b254747f1..b504cf09e 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageFlags.java @@ -12,7 +12,7 @@ public final class SqueakImageFlags { @CompilationFinal private long oldBaseAddress = -1; - @CompilationFinal private int fullScreenFlag = 0; + @CompilationFinal private int fullScreenFlag; @CompilationFinal private int imageFloatsBigEndian; @CompilationFinal private boolean flagInterpretedMethods; @CompilationFinal private boolean preemptionYields; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java index 6ad8f268d..38184cdca 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/image/SqueakImageReader.java @@ -48,11 +48,11 @@ public final class SqueakImageReader { private int headerFlags; private short maxExternalSemaphoreTableSize; private long firstSegmentSize; - private int position = 0; + private int position; private long currentAddressSwizzle; private final byte[] emptyBytes = new byte[0]; - private SqueakImageChunk freePageList = null; + private SqueakImageChunk freePageList; private SqueakImageReader(final SqueakImageContext image) { final TruffleFile truffleFile = image.env.getPublicTruffleFile(image.getImagePath()); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java index 15daaf618..cdc413953 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/interop/JavaObjectWrapper.java @@ -165,7 +165,7 @@ public Object getMembers(@SuppressWarnings("unused") final boolean includeIntern members.add(WRAPPED_MEMBER); members.addAll(getFields().keySet()); members.addAll(getMethods().keySet()); - cachedMembers = new InteropArray(members.toArray(new String[members.size()])); + cachedMembers = new InteropArray(members.toArray(new String[0])); } return cachedMembers; } diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java index 92d2b4d54..180c7b646 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/io/SqueakDisplay.java @@ -28,7 +28,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayDeque; -import java.util.Iterator; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -74,11 +73,10 @@ public final class SqueakDisplay implements SqueakDisplayInterface { @CompilationFinal private int inputSemaphoreIndex = -1; - public int buttons = 0; - private Dimension rememberedWindowSize = null; - private Point rememberedWindowLocation = null; - private boolean deferUpdates = false; - private int[] cursorMergedWords = new int[SqueakIOConstants.CURSOR_HEIGHT]; + public int buttons; + private Dimension rememberedWindowSize; + private Point rememberedWindowLocation; + private boolean deferUpdates; public SqueakDisplay(final SqueakImageContext image) { this.image = image; @@ -313,16 +311,13 @@ public void setCursor(final int[] cursorWords, final int[] mask, final int width canvas.setCursor(cursor); } - private int[] mergeCursorWithMask(final int[] cursorWords, final int[] maskWords) { - int cursorWord; - int maskWord; - int bit; - int merged; + private static int[] mergeCursorWithMask(final int[] cursorWords, final int[] maskWords) { + final int[] cursorMergedWords = new int[SqueakIOConstants.CURSOR_HEIGHT]; for (int y = 0; y < SqueakIOConstants.CURSOR_HEIGHT; y++) { - cursorWord = cursorWords[y]; - maskWord = maskWords[y]; - bit = 0x80000000; - merged = 0; + final int cursorWord = cursorWords[y]; + final int maskWord = maskWords[y]; + int bit = 0x80000000; + int merged = 0; for (int x = 0; x < SqueakIOConstants.CURSOR_WIDTH; x++) { merged = merged | (maskWord & bit) >> x | (cursorWord & bit) >> x + 1; bit = bit >>> 1; @@ -433,14 +428,8 @@ public void drop(final DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); try { @SuppressWarnings("unchecked") - final List l = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor); - final Iterator iter = l.iterator(); - final String[] fileList = new String[l.size()]; - int i = 0; - while (iter.hasNext()) { - fileList[i++] = iter.next().getCanonicalPath(); - } - image.dropPluginFileList = fileList; + final List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor); + image.dropPluginFileList = fileList.toArray(new String[0]); addDragEvent(DRAG.DROP, dtde.getLocation()); dtde.getDropTargetContext().dropComplete(true); return; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ClassObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ClassObject.java index 014adb59b..52498795d 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ClassObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ClassObject.java @@ -53,7 +53,7 @@ public final class ClassObject extends AbstractSqueakObjectWithClassAndHash { private final CyclicAssumption methodDictStable = new CyclicAssumption("Method dictionary stability"); private final CyclicAssumption classFormatStable = new CyclicAssumption("Class format stability"); - @CompilationFinal private boolean instancesAreClasses = false; + @CompilationFinal private boolean instancesAreClasses; private ClassObject superclass; @CompilationFinal private VariablePointersObject methodDict; @@ -445,7 +445,7 @@ public Object[] listInteropMembers() { } lookupClass = lookupClass.getSuperclassOrNull(); } - return methodNames.toArray(new String[methodNames.size()]); + return methodNames.toArray(new String[0]); } public int getBasicInstanceSize() { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java index c519590fa..23aa77c7f 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledCodeObject.java @@ -63,7 +63,7 @@ public enum SLOT_IDENTIFIER { @CompilationFinal protected int numArgs; @CompilationFinal protected int numLiterals; @CompilationFinal protected boolean hasPrimitive; - @CompilationFinal protected boolean needsLargeFrame = false; + @CompilationFinal protected boolean needsLargeFrame; @CompilationFinal protected int numTemps; @CompilationFinal(dimensions = 1) private CompiledBlockObject[] innerBlocks; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledMethodObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledMethodObject.java index 1c087ccf6..7fb2eb313 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledMethodObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/CompiledMethodObject.java @@ -74,19 +74,10 @@ public String toString() { return className + ">>" + getNotNilSelector(); } - public String getNotNilSelector() { + private String getNotNilSelector() { CompilerAsserts.neverPartOfCompilation(); - String selector = "DoIt"; final NativeObject selectorObj = getCompiledInSelector(); - if (selectorObj != null) { - selector = selectorObj.asStringUnsafe(); - } else if (getNumArgs() > 0) { - selector += ":"; - for (int i = 1; i < getNumArgs(); i++) { - selector += "with:"; - } - } - return selector; + return selectorObj == null ? "DoIt" : selectorObj.asStringUnsafe(); } @Override diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ContextObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ContextObject.java index 239f76f7c..6604fe0e7 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ContextObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/ContextObject.java @@ -44,8 +44,8 @@ public final class ContextObject extends AbstractSqueakObjectWithHash { @CompilationFinal private MaterializedFrame truffleFrame; @CompilationFinal private PointersObject process; @CompilationFinal private int size; - private boolean hasModifiedSender = false; - private boolean escaped = false; + private boolean hasModifiedSender; + private boolean escaped; private ContextObject(final SqueakImageContext image, final long hash) { super(image, hash); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/FloatObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/FloatObject.java index 2417bfa1f..ea3ef6cbc 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/FloatObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/FloatObject.java @@ -146,7 +146,7 @@ public void write(final SqueakImageWriter writer) { @Override public String toString() { CompilerAsserts.neverPartOfCompilation(); - return "" + doubleValue; + return Double.toString(doubleValue); } public FloatObject shallowCopy() { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/WeakVariablePointersObject.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/WeakVariablePointersObject.java index 76d870168..fab89da6c 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/WeakVariablePointersObject.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/model/WeakVariablePointersObject.java @@ -167,19 +167,19 @@ public void write(final SqueakImageWriter writer) { @Override public String toString() { CompilerAsserts.neverPartOfCompilation(); - String prefix = ""; + final StringBuilder sb = new StringBuilder(64); if (variablePart.length > 0) { final Object referent = variablePart[0].get(); - prefix = "[" + referent; + sb.append('[').append(referent); if (variablePart[0].isEnqueued()) { - prefix += " (marked as garbage)"; + sb.append(" (marked as garbage)"); } if (variablePart.length > 1) { - prefix += "..."; + sb.append("..."); } - prefix += "]"; + sb.append(']'); } - return prefix + " a " + getSqueakClassName() + " @" + Integer.toHexString(hashCode()) + " of size " + variablePart.length; + return sb.append(" a ").append(getSqueakClassName()).append(" @").append(Integer.toHexString(hashCode())).append(" of size ").append(variablePart.length).toString(); } /* diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyFromStackNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyFromStackNode.java index c12ce2f34..d00317d94 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyFromStackNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyFromStackNode.java @@ -79,9 +79,9 @@ protected final Object doPrimitiveEagerly(final VirtualFrame frame, @SuppressWar * send the primitive eagerly or not. This is useful to avoid rewriting primitives that set up * the image and then are retried in their fallback code (e.g. primitiveCopyBits). */ - protected static final class PrimitiveFailedCounter { + public static final class PrimitiveFailedCounter { private static final int PRIMITIVE_FAILED_THRESHOLD = 3; - private int count = 0; + private int count; protected static PrimitiveFailedCounter create() { return new PrimitiveFailedCounter(); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyNode.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyNode.java index 301716d47..0030fa170 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyNode.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/DispatchEagerlyNode.java @@ -18,6 +18,7 @@ import de.hpi.swa.trufflesqueak.exceptions.PrimitiveExceptions.PrimitiveFailed; import de.hpi.swa.trufflesqueak.model.CompiledMethodObject; +import de.hpi.swa.trufflesqueak.nodes.DispatchEagerlyFromStackNode.PrimitiveFailedCounter; import de.hpi.swa.trufflesqueak.nodes.context.frame.CreateEagerArgumentsNode; import de.hpi.swa.trufflesqueak.nodes.context.frame.GetContextOrMarkerNode; import de.hpi.swa.trufflesqueak.nodes.context.frame.GetOrCreateContextNode; @@ -57,24 +58,6 @@ protected static final Object doPrimitiveEagerly(final VirtualFrame frame, @Supp } } - /* - * Counts how often a primitive has failed and indicates whether this node should continue to - * send the primitive eagerly or not. This is useful to avoid rewriting primitives that set up - * the image and then are retried in their fallback code (e.g. primitiveCopyBits). - */ - protected static final class PrimitiveFailedCounter { - private static final int PRIMITIVE_FAILED_THRESHOLD = 3; - private int count = 0; - - protected static PrimitiveFailedCounter create() { - return new PrimitiveFailedCounter(); - } - - protected boolean shouldNoLongerSendEagerly() { - return ++count > PRIMITIVE_FAILED_THRESHOLD; - } - } - @Specialization(guards = {"method == cachedMethod"}, // limit = "INLINE_CACHE_SIZE", assumptions = {"cachedMethod.getCallTargetStable()", "cachedMethod.getDoesNotNeedSenderAssumption()"}, replaces = "doPrimitiveEagerly") protected static final Object doDirect(final VirtualFrame frame, @SuppressWarnings("unused") final CompiledMethodObject method, final Object[] receiverAndArguments, diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/JPEGReader.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/JPEGReader.java index 044ac50ff..e16e0ab8c 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/JPEGReader.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/JPEGReader.java @@ -95,7 +95,7 @@ public final class JPEGReader { private int[][] yBlocks = new int[128][]; private int[] yComponent = new int[11]; - private boolean failed = false; + private boolean failed; /* JPEGReaderPlugin>>#cbColorComponentFrom: */ private boolean cbColorComponentFrom(final Object oop) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java index 456e05b38..cb302ef66 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakFFIPrims.java @@ -218,20 +218,19 @@ protected static final String getPathOrFail(final SqueakImageContext image, fina } private static String generateNfiCodeParamsString(final List argumentList) { - String nfiCodeParams = ""; + final StringBuilder nfiCodeParams = new StringBuilder(32); if (!argumentList.isEmpty()) { final String returnType = argumentList.get(0); argumentList.remove(0); if (!argumentList.isEmpty()) { - nfiCodeParams = "(" + String.join(",", argumentList) + ")"; + nfiCodeParams.append('(').append(String.join(",", argumentList)).append(')'); } else { - nfiCodeParams = "()"; + nfiCodeParams.append("()"); } - nfiCodeParams += ":" + returnType + ";"; + nfiCodeParams.append(':').append(returnType).append(';'); } - return nfiCodeParams; + return nfiCodeParams.toString(); } - } @GenerateNodeFactory diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakSSL.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakSSL.java index 34e5688cd..b9702276e 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakSSL.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/SqueakSSL.java @@ -46,6 +46,7 @@ import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveInterfaces.TernaryPrimitive; import de.hpi.swa.trufflesqueak.nodes.primitives.PrimitiveInterfaces.UnaryPrimitiveWithoutFallback; import de.hpi.swa.trufflesqueak.nodes.primitives.SqueakPrimitive; +import de.hpi.swa.trufflesqueak.util.MiscUtils; /** * Implement Squeak SSL primitives using {@link SSLEngine}. @@ -599,7 +600,7 @@ private static void runTasks(final SqSSL ssl) { @TruffleBoundary private static void setUp(final SqSSL ssl) { - if (certificateName != null && !certificateName.trim().isEmpty()) { + if (certificateName != null && !MiscUtils.isBlank(certificateName)) { initializeWithCertificate(ssl, certificateName); } else { initializeWithDefaultCertificates(ssl); @@ -628,7 +629,7 @@ private static void initializeWithDefaultCertificates(final SqSSL ssl) { } private static void ensureEngine(final SqSSL ssl) { - if (ssl.serverName != null && !ssl.serverName.trim().isEmpty()) { + if (ssl.serverName != null && !MiscUtils.isBlank(ssl.serverName)) { ssl.engine = ssl.context.createSSLEngine(ssl.serverName, -1); } else { ssl.engine = ssl.context.createSSLEngine(); diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/Zip.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/Zip.java index 95b1a39ef..4d2d20a09 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/Zip.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/Zip.java @@ -172,12 +172,12 @@ public final class Zip { /* 236 */ 284, 284, 284, 284, /* 240 */ 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284 }; - private int zipPosition = 0; - private int zipReadLimit = 0; - private byte[] zipSource = null; - private int zipSourceLimit = 0; - private int zipSourcePos = 0; - private int zipState = 0; + private int zipPosition; + private int zipReadLimit; + private byte[] zipSource; + private int zipSourceLimit; + private int zipSourcePos; + private int zipState; /* * Compare the two strings and return the length of matching characters. minLength is a lower diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/network/Resolver.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/network/Resolver.java index e8d340366..7d1279229 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/network/Resolver.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/plugins/network/Resolver.java @@ -30,8 +30,8 @@ long id() { } } - private static InetAddress anyLocalAddress = null; - private static InetAddress loopbackAddress = null; + private static InetAddress anyLocalAddress; + private static InetAddress loopbackAddress; private static byte[] lastNameLookup; private static String lastAddressLookup; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java index 8f3443883..e38dd9f34 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/PrimitiveNodeFactory.java @@ -168,7 +168,7 @@ public static String[] getPluginNames() { for (final String key : PLUGIN_MAP.getKeys()) { target.add(key); } - return target.toArray(new String[target.size()]); + return target.toArray(new String[0]); } private static AbstractPrimitiveNode createInstance(final CompiledMethodObject method, final boolean useStack, final NodeFactory nodeFactory) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ContextPrimitives.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ContextPrimitives.java index caf7d5a7f..714486fbf 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ContextPrimitives.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/nodes/primitives/impl/ContextPrimitives.java @@ -151,7 +151,7 @@ private void terminateBetween(final FrameMarker start, final ContextObject end) assert start != null : "Unexpected `null` value"; final ContextObject[] bottomContextOnTruffleStack = new ContextObject[1]; final ContextObject result = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor() { - boolean foundMyself = false; + boolean foundMyself; @Override public ContextObject visitFrame(final FrameInstance frameInstance) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/tools/SqueakMessageInterceptor.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/tools/SqueakMessageInterceptor.java index 1db9b0ab0..00374d851 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/tools/SqueakMessageInterceptor.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/tools/SqueakMessageInterceptor.java @@ -24,7 +24,7 @@ public final class SqueakMessageInterceptor extends TruffleInstrument { private static final String DEFAULTS = "TestCase>>runCase,TestCase>>logFailure:,TestCase>>signalFailure:,Object>>halt,Object>>inform:," + // "SmalltalkImage>>logSqueakError:inContext:,UnhandledError>>defaultAction,SyntaxErrorNotification>>setClass:code:doitFlag:errorMessage:location:"; - private static String[] breakpoints = null; + private static String[] breakpoints; public static void enableIfRequested(final SqueakLanguage.Env env) { if (env.getOptions().hasBeenSet(SqueakOptions.InterceptMessages)) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/ArrayUtils.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/ArrayUtils.java index 267098f7a..5857a5a4e 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/ArrayUtils.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/ArrayUtils.java @@ -112,7 +112,7 @@ public static byte[] swapOrderInPlace(final byte[] bytes) { @TruffleBoundary public static Object[] toArray(final AbstractCollection list) { - return list.toArray(new Object[list.size()]); + return list.toArray(new Object[0]); } @TruffleBoundary diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/DebugUtils.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/DebugUtils.java index 97c6fafae..57dfe3e52 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/DebugUtils.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/DebugUtils.java @@ -57,30 +57,20 @@ public static void dumpState() { public static void dumpThreads(final StringBuilder sb) { CompilerAsserts.neverPartOfCompilation("For debugging purposes only"); - sb.append("\r\n\r\n\r\n"); - sb.append("Total number of threads started: "); - sb.append(ManagementFactory.getThreadMXBean().getTotalStartedThreadCount()); - sb.append("\r\n\r\n"); + sb.append("\r\n\r\n\r\n").append("Total number of threads started: ").append(ManagementFactory.getThreadMXBean().getTotalStartedThreadCount()).append("\r\n\r\n"); final Runtime r = Runtime.getRuntime(); - sb.append("Total Memory : "); - sb.append(r.totalMemory()); - sb.append("\r\n"); - sb.append("Max Memory : "); - sb.append(r.maxMemory()); - sb.append("\r\n"); - sb.append("Free Memory : "); - sb.append(r.freeMemory()); - sb.append("\r\n\r\n"); + sb.append("Total Memory : ").append(r.totalMemory()).append("\r\n").append("Max Memory : ").append(r.maxMemory()).append("\r\n").append("Free Memory : ").append(r.freeMemory()).append( + "\r\n\r\n"); final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true); for (final ThreadInfo info : threads) { - sb.append("\"" + info.getThreadName() + "\" Id=" + info.getThreadId() + " " + info.getThreadState()); + sb.append("\"").append(info.getThreadName()).append("\" Id=").append(info.getThreadId()).append(' ').append(info.getThreadState()); if (info.getLockName() != null) { - sb.append(" on " + info.getLockName()); + sb.append(" on ").append(info.getLockName()); } if (info.getLockOwnerName() != null) { - sb.append(" owned by \"" + info.getLockOwnerName() + "\" Id=" + info.getLockOwnerId()); + sb.append(" owned by \"").append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId()); } if (info.isSuspended()) { sb.append(" (suspended)"); @@ -92,22 +82,19 @@ public static void dumpThreads(final StringBuilder sb) { int i = 0; for (; i < info.getStackTrace().length; i++) { final StackTraceElement ste = info.getStackTrace()[i]; - sb.append("\tat " + ste.toString()); + sb.append("\tat ").append(ste.toString()); sb.append("\r\n"); if (i == 0 && info.getLockInfo() != null) { final Thread.State ts = info.getThreadState(); switch (ts) { case BLOCKED: - sb.append("\t- blocked on " + info.getLockInfo()); - sb.append("\r\n"); + sb.append("\t- blocked on ").append(info.getLockInfo()).append("\r\n"); break; case WAITING: - sb.append("\t- waiting on " + info.getLockInfo()); - sb.append("\r\n"); + sb.append("\t- waiting on ").append(info.getLockInfo()).append("\r\n"); break; case TIMED_WAITING: - sb.append("\t- waiting on " + info.getLockInfo()); - sb.append("\r\n"); + sb.append("\t- waiting on ").append(info.getLockInfo()).append("\r\n"); break; default: } @@ -115,8 +102,7 @@ public static void dumpThreads(final StringBuilder sb) { for (final MonitorInfo mi : info.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { - sb.append("\t- locked " + mi); - sb.append("\r\n"); + sb.append("\t- locked ").append(mi).append("\r\n"); } } } @@ -127,11 +113,9 @@ public static void dumpThreads(final StringBuilder sb) { final LockInfo[] locks = info.getLockedSynchronizers(); if (locks.length > 0) { - sb.append("\r\n\tNumber of locked synchronizers = " + locks.length); - sb.append("\r\n"); + sb.append("\r\n\tNumber of locked synchronizers = ").append(locks.length).append("\r\n"); for (final LockInfo li : locks) { - sb.append("\t- " + li); - sb.append("\r\n"); + sb.append("\t- ").append(li).append("\r\n"); } } @@ -142,15 +126,11 @@ public static void dumpThreads(final StringBuilder sb) { public static String currentState() { CompilerAsserts.neverPartOfCompilation("For debugging purposes only"); final SqueakImageContext image = SqueakLanguage.getContext(); - final StringBuilder b = new StringBuilder(); + final StringBuilder b = new StringBuilder(64); b.append("\nImage processes state\n"); final PointersObject activeProcess = GetActiveProcessNode.getSlow(image); final long activePriority = (long) activeProcess.instVarAt0Slow(PROCESS.PRIORITY); - b.append("*Active process @"); - b.append(Integer.toHexString(activeProcess.hashCode())); - b.append(" priority "); - b.append(activePriority); - b.append('\n'); + b.append("*Active process @").append(Integer.toHexString(activeProcess.hashCode())).append(" priority ").append(activePriority).append('\n'); final Object interruptSema = image.getSpecialObject(SPECIAL_OBJECT.THE_INTERRUPT_SEMAPHORE); printSemaphoreOrNil(b, "*Interrupt semaphore @", interruptSema, true); final Object timerSema = image.getSpecialObject(SPECIAL_OBJECT.THE_TIMER_SEMAPHORE); @@ -214,8 +194,8 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject CompilerAsserts.neverPartOfCompilation("For debugging purposes only"); final Object[] frameArguments = frame.getArguments(); final Object receiver = frameArguments[3]; - final StringBuilder b = new StringBuilder("\n\t\t- Receiver: "); - b.append(receiver); + final StringBuilder b = new StringBuilder(256); + b.append("\n\t\t- Receiver: ").append(receiver); if (receiver instanceof ContextObject) { final ContextObject context = (ContextObject) receiver; if (context.hasTruffleFrame()) { @@ -231,11 +211,7 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject final int numArgs = receiverCode.getNumArgs(); for (int i = 0; i < numArgs; i++) { final Object value = receiverFrameArguments[i + 4]; - b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t-> a" : "\t\t\t\t\t\t\ta"); - b.append(i); - b.append("\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t-> a" : "\t\t\t\t\t\t\ta").append(i).append('\t').append(value).append('\n'); } final FrameSlot[] stackSlots = receiverCode.getStackSlotsUnsafe(); boolean addedSeparator = false; @@ -246,11 +222,7 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject initialStackp = receiverCode.getNumArgsAndCopied(); for (int i = numArgs; i < initialStackp; i++) { final Object value = receiverFrameArguments[i + 4]; - b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t-> c" : "\t\t\t\t\t\t\tc"); - b.append(i); - b.append("\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t-> c" : "\t\t\t\t\t\t\tc").append(i).append('\t').append(value).append('\n'); } } else { initialStackp = receiverCode.getNumTemps(); @@ -258,11 +230,7 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject final FrameSlot slot = stackSlots[i]; Object value = null; if (slot != null && (value = receiverFrame.getValue(slot)) != null) { - b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t-> t" : "\t\t\t\t\t\t\tt"); - b.append(i); - b.append("\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t-> t" : "\t\t\t\t\t\t\tt").append(i).append('\t').append(value).append('\n'); } } } @@ -275,9 +243,7 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject addedSeparator = true; b.append("\t\t\t\t\t\t\t------------------------------------------------\n"); } - b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t\t->\t" : "\t\t\t\t\t\t\t\t\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t\t\t\t->\t" : "\t\t\t\t\t\t\t\t\t").append(value).append('\n'); } else { j = i; if (zeroBasedStackp == i) { @@ -304,11 +270,7 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject final int numArgs = code.getNumArgs(); for (int i = 0; i < numArgs; i++) { final Object value = frameArguments[i + 4]; - b.append(zeroBasedStackp == i ? "\t\t\t\t-> a" : "\t\t\t\t\ta"); - b.append(i); - b.append("\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t-> a" : "\t\t\t\t\ta").append(i).append('\t').append(value).append('\n'); } final FrameSlot[] stackSlots = code.getStackSlotsUnsafe(); boolean addedSeparator = false; @@ -318,22 +280,14 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject initialStackp = code.getNumArgsAndCopied(); for (int i = numArgs; i < initialStackp; i++) { final Object value = frameArguments[i + 4]; - b.append(zeroBasedStackp == i ? "\t\t\t\t-> c" : "\t\t\t\t\tc"); - b.append(i); - b.append("\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t-> c" : "\t\t\t\t\tc").append(i).append('\t').append(value).append('\n'); } } else { initialStackp = code.getNumTemps(); for (int i = numArgs; i < initialStackp; i++) { final FrameSlot slot = stackSlots[i]; final Object value = frame.getValue(slot); - b.append(zeroBasedStackp == i ? "\t\t\t\t-> t" : "\t\t\t\t\tt"); - b.append(i); - b.append("\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t-> t" : "\t\t\t\t\tt").append(i).append('\t').append(value).append('\n'); } } int j = initialStackp; @@ -345,9 +299,7 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject addedSeparator = true; b.append("\t\t\t\t\t------------------------------------------------\n"); } - b.append(zeroBasedStackp == i ? "\t\t\t\t\t->\t" : "\t\t\t\t\t\t\t"); - b.append(value); - b.append("\n"); + b.append(zeroBasedStackp == i ? "\t\t\t\t\t->\t" : "\t\t\t\t\t\t\t").append(value).append('\n'); } else { j = i; if (zeroBasedStackp == i) { @@ -371,18 +323,14 @@ public static String stackFor(final VirtualFrame frame, final CompiledCodeObject private static void printSemaphoreOrNil(final StringBuilder b, final String label, final Object semaphoreOrNil, final boolean printIfNil) { if (semaphoreOrNil instanceof PointersObject) { - b.append(label); - b.append(Integer.toHexString(semaphoreOrNil.hashCode())); - b.append(" with "); - b.append(((AbstractPointersObject) semaphoreOrNil).instVarAt0Slow(SEMAPHORE.EXCESS_SIGNALS)); - b.append(" excess signals"); + b.append(label).append(Integer.toHexString(semaphoreOrNil.hashCode())).append(" with ").append(((AbstractPointersObject) semaphoreOrNil).instVarAt0Slow(SEMAPHORE.EXCESS_SIGNALS)).append( + " excess signals"); if (!printLinkedList(b, "", (PointersObject) semaphoreOrNil)) { b.append(" and no processes\n"); } } else { if (printIfNil) { - b.append(label); - b.append(" is nil\n"); + b.append(label).append(" is nil\n"); } } } @@ -390,8 +338,7 @@ private static void printSemaphoreOrNil(final StringBuilder b, final String labe private static boolean printLinkedList(final StringBuilder b, final String label, final PointersObject linkedList) { Object temp = linkedList.instVarAt0Slow(LINKED_LIST.FIRST_LINK); if (temp instanceof PointersObject) { - b.append(label); - b.append(" and process"); + b.append(label).append(" and process"); if (temp != linkedList.instVarAt0Slow(LINKED_LIST.LAST_LINK)) { b.append("es:\n"); } else { @@ -402,16 +349,10 @@ private static boolean printLinkedList(final StringBuilder b, final String label final Object aContext = aProcess.instVarAt0Slow(PROCESS.SUSPENDED_CONTEXT); if (aContext instanceof ContextObject) { assert ((ContextObject) aContext).getProcess() == null || ((ContextObject) aContext).getProcess() == aProcess; - b.append("\tprocess @"); - b.append(Integer.toHexString(aProcess.hashCode())); - b.append(" with suspended context "); - b.append(aContext); - b.append(" and stack trace:\n"); + b.append("\tprocess @").append(Integer.toHexString(aProcess.hashCode())).append(" with suspended context ").append(aContext).append(" and stack trace:\n"); printSqMaterializedStackTraceOn(b, (ContextObject) aContext); } else { - b.append("\tprocess @"); - b.append(Integer.toHexString(aProcess.hashCode())); - b.append(" with suspended context nil\n"); + b.append("\tprocess @").append(Integer.toHexString(aProcess.hashCode())).append(" with suspended context nil\n"); } temp = aProcess.instVarAt0Slow(PROCESS.NEXT_LINK); } @@ -425,14 +366,12 @@ private static void printSqMaterializedStackTraceOn(final StringBuilder b, final ContextObject current = context; while (current != null && current.hasTruffleFrame()) { final Object[] rcvrAndArgs = current.getReceiverAndNArguments(); - b.append(MiscUtils.format("%s #(%s) [%s]", current, ArrayUtils.toJoinedString(", ", rcvrAndArgs), current.getFrameMarker())); - b.append('\n'); + b.append(MiscUtils.format("%s #(%s) [%s]", current, ArrayUtils.toJoinedString(", ", rcvrAndArgs), current.getFrameMarker())).append('\n'); final Object sender = current.getFrameSender(); if (sender == NilObject.SINGLETON) { break; } else if (sender instanceof FrameMarker) { - b.append(sender); - b.append('\n'); + b.append(sender).append('\n'); break; } else { current = (ContextObject) sender; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/InterruptHandlerState.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/InterruptHandlerState.java index ea94a09dc..0f3d5306e 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/InterruptHandlerState.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/InterruptHandlerState.java @@ -27,9 +27,9 @@ public final class InterruptHandlerState { private final ArrayDeque semaphoresToSignal = new ArrayDeque<>(); private boolean isActive = true; - protected long nextWakeupTick = 0; - protected boolean interruptPending = false; - private boolean pendingFinalizationSignals = false; + protected long nextWakeupTick; + protected boolean interruptPending; + private boolean pendingFinalizationSignals; /** * `shouldTrigger` is set to `true` by a dedicated thread. To guarantee atomicity, it would be @@ -37,7 +37,7 @@ public final class InterruptHandlerState { * cannot be moved by the Graal compiler during compilation. Since atomicity is not needed for * the interrupt handler mechanism, we can use a standard boolean here for better compilation. */ - private boolean shouldTrigger = false; + private boolean shouldTrigger; @CompilationFinal private PointersObject interruptSemaphore; private PointersObject timerSemaphore; diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/MiscUtils.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/MiscUtils.java index 4a82aa4a1..66c23566f 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/MiscUtils.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/MiscUtils.java @@ -155,7 +155,7 @@ public static long getStartTime() { @TruffleBoundary public static String getSystemProperties() { final Properties properties = System.getProperties(); - final StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(256); sb.append("\n\n== System Properties =================================>\n"); final Object[] keys = properties.keySet().toArray(); Arrays.sort(keys); @@ -192,6 +192,15 @@ public static String getVMPath() { return System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + binaryName; } + public static boolean isBlank(final String str) { + for (int i = 0; i < str.length(); i++) { + if (!Character.isWhitespace(str.charAt(i))) { + return false; + } + } + return true; + } + /* Wraps bitmap in a BufferedImage for efficient drawing. */ @TruffleBoundary public static BufferedImage new32BitBufferedImage(final int[] words, final int width, final int height) { diff --git a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/SqueakBytecodeDecoder.java b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/SqueakBytecodeDecoder.java index 5b85b45fd..e62247d08 100644 --- a/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/SqueakBytecodeDecoder.java +++ b/src/de.hpi.swa.trufflesqueak/src/de/hpi/swa/trufflesqueak/util/SqueakBytecodeDecoder.java @@ -254,15 +254,15 @@ public static String decodeToString(final CompiledCodeObject code) { final byte[] bytes = code.getBytes(); while (bytecodeIndex < trailerPosition) { final int currentByte = Byte.toUnsignedInt(bytes[bytecodeIndex]); - sb.append(lineIndex + " "); - for (int j = 0; j < indent; j++) { - sb.append(" "); + sb.append(lineIndex); + for (int j = 0; j < 1 + indent; j++) { + sb.append(' '); } final int numBytecodes = decodeNumBytes(code, bytecodeIndex); - sb.append("<"); + sb.append('<'); for (int j = bytecodeIndex; j < bytecodeIndex + numBytecodes; j++) { if (j > bytecodeIndex) { - sb.append(" "); + sb.append(' '); } if (j < bytes.length) { sb.append(String.format("%02X", bytes[j])); @@ -278,7 +278,7 @@ public static String decodeToString(final CompiledCodeObject code) { lineIndex++; bytecodeIndex += numBytecodes; if (bytecodeIndex < trailerPosition) { - sb.append("\n"); + sb.append('\n'); } } return sb.toString();