# HG changeset patch # User Doug Simon # Date 1437696702 -7200 # Node ID cd04ef3c7c49c1e9df37a9db34f25579fd4e2f5f # Parent 2c87ecb88c81b112c16a6e77c01f4f3741ed2945 Remove unneeded files. diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/BackendOptions.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.compiler.common; - -import static com.oracle.graal.compiler.common.BackendOptions.UserOptions.*; -import static com.oracle.graal.compiler.common.GraalOptions.*; -import jdk.internal.jvmci.options.*; -import jdk.internal.jvmci.options.DerivedOptionValue.*; - -/** - * Options to control the backend configuration. - */ -public final class BackendOptions { - - public static class UserOptions { - // @formatter:off - @Option(help = "Destruct SSA LIR eagerly (before other LIR phases).", type = OptionType.Debug) - public static final OptionValue LIREagerSSADestruction = new OptionValue<>(false); - // @formatter:on - } - - /* Create SSA LIR during LIR generation. */ - public static final DerivedOptionValue ConstructionSSAlirDuringLirBuilding = new DerivedOptionValue<>(new OptionSupplier() { - private static final long serialVersionUID = 7657622005438210681L; - - public Boolean get() { - return SSA_LIR.getValue(); - } - }); - - public enum LSRAVariant { - NONSSA_LSAR, - SSA_LSRA - } - - public static final DerivedOptionValue LinearScanVariant = new DerivedOptionValue<>(new OptionSupplier() { - private static final long serialVersionUID = 364925071685235153L; - - public LSRAVariant get() { - if (SSA_LIR.getValue() && !LIREagerSSADestruction.getValue()) { - return LSRAVariant.SSA_LSRA; - } - return LSRAVariant.NONSSA_LSAR; - } - }); - - /* Does the backend emit stack to stack moves?. */ - public static final DerivedOptionValue ShouldOptimizeStackToStackMoves = new DerivedOptionValue<>(new OptionSupplier() { - private static final long serialVersionUID = 2366072840509944317L; - - public Boolean get() { - switch (LinearScanVariant.getValue()) { - case SSA_LSRA: - return true; - } - return false; - } - }); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/CompilerThread.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/CompilerThread.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.compiler; - -import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess; -import com.oracle.graal.debug.*; - -/** - * A compiler thread is a daemon thread that runs at {@link Thread#MAX_PRIORITY} and executes in the - * context of a thread-local {@linkplain JVMCIDebugConfig debug configuration}. - */ -public class CompilerThread extends Thread { - - private final DebugConfigAccess debugConfigAccess; - - public CompilerThread(Runnable r, String namePrefix, DebugConfigAccess debugConfigAccess) { - super(r); - this.setName(namePrefix + "-" + this.getId()); - this.setPriority(Thread.MAX_PRIORITY); - this.setDaemon(true); - this.debugConfigAccess = debugConfigAccess; - } - - @Override - public void run() { - JVMCIDebugConfig debugConfig = debugConfigAccess.getDebugConfig(); - setContextClassLoader(getClass().getClassLoader()); - try { - super.run(); - } finally { - if (debugConfig != null) { - for (DebugDumpHandler dumpHandler : debugConfig.dumpHandlers()) { - try { - dumpHandler.close(); - } catch (Throwable t) { - } - } - } - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/CompilerThreadFactory.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/CompilerThreadFactory.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.compiler; - -import java.util.concurrent.*; - -import com.oracle.graal.debug.*; - -/** - * Facility for creating {@linkplain CompilerThread compiler threads}. - */ -public class CompilerThreadFactory implements ThreadFactory { - - /** - * Capability to get a thread-local debug configuration for the current thread. - */ - public interface DebugConfigAccess { - /** - * Get a thread-local debug configuration for the current thread. This will be null if - * debugging is disabled. - */ - JVMCIDebugConfig getDebugConfig(); - } - - protected final String threadNamePrefix; - protected final DebugConfigAccess debugConfigAccess; - - public CompilerThreadFactory(String threadNamePrefix, DebugConfigAccess debugConfigAccess) { - this.threadNamePrefix = threadNamePrefix; - this.debugConfigAccess = debugConfigAccess; - } - - public Thread newThread(Runnable r) { - return new CompilerThread(r, threadNamePrefix, debugConfigAccess); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java --- a/graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugHistogramTest.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2013, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.test; - -import java.io.*; - -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.internal.*; - -import org.junit.*; - -public class DebugHistogramTest { - - @Test - public void testEmptyHistogram() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); - String line = outputStream.toString().split("\r?\n")[0]; - Assert.assertEquals("TestHistogram is empty.", line); - - outputStream.reset(); - new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); - Assert.assertEquals("", outputStream.toString()); - } - - @Test - public void testSingleEntryHistogram() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - histogram.add(new Integer(1)); - histogram.add(new Integer(1)); - new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); - String[] lines = outputStream.toString().split("\r?\n"); - // @formatter:off - String[] expected = { - "TestHistogram has 1 unique elements and 2 total elements:", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - "| 1 | 2 | ==================================================================================================== |", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - - outputStream.reset(); - new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); - lines = outputStream.toString().split("\r?\n"); - // @formatter:off - expected = new String[] { - "TestHistogram <- c(2);", - "names(TestHistogram) <- c(\"1\");" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - } - - @Test - public void testMultipleEntryHistogram() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - histogram.add(new Integer(1)); - histogram.add(new Integer(2)); - histogram.add(new Integer(2)); - new DebugHistogramAsciiPrinter(new PrintStream(outputStream)).print(histogram); - String[] lines = outputStream.toString().split("\r?\n"); - // @formatter:off - String[] expected = new String[] { - "TestHistogram has 2 unique elements and 3 total elements:", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------", - "| 2 | 2 | ==================================================================================================== |", - "| 1 | 1 | ================================================== |", - "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - - outputStream.reset(); - new DebugHistogramRPrinter(new PrintStream(outputStream)).print(histogram); - lines = outputStream.toString().split("\r?\n"); - // @formatter:off - expected = new String[] { - "TestHistogram <- c(2, 1);", - "names(TestHistogram) <- c(\"2\", \"1\");" - }; - // @formatter:on - Assert.assertArrayEquals(expected, lines); - } - - @Test - public void testTooLongValueString() { - DebugHistogram histogram = Debug.createHistogram("TestHistogram"); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - histogram.add("MyCustomValue"); - new DebugHistogramAsciiPrinter(new PrintStream(outputStream), Integer.MAX_VALUE, 10, 10, 1).print(histogram); - String[] lines = outputStream.toString().split("\r?\n"); - Assert.assertEquals(4, lines.length); - Assert.assertEquals("TestHistogram has 1 unique elements and 1 total elements:", lines[0]); - Assert.assertEquals("----------------------------------------", lines[1]); - Assert.assertEquals("| MyCusto... | 1 | ========== |", lines[2]); - Assert.assertEquals("----------------------------------------", lines[3]); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugTimerTest.java --- a/graal/com.oracle.graal.debug.test/src/com/oracle/graal/debug/test/DebugTimerTest.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.test; - -import static org.junit.Assert.*; - -import java.lang.management.*; - -import jdk.internal.jvmci.debug.*; - -import com.oracle.graal.debug.*; - -import org.junit.*; - -public class DebugTimerTest { - - private static final ThreadMXBean threadMXBean = Management.getThreadMXBean(); - - @Before - public void checkCapabilities() { - Assume.assumeTrue("skipping management interface test", threadMXBean.isCurrentThreadCpuTimeSupported()); - } - - /** - * Actively spins the current thread for at least a given number of milliseconds in such a way - * that timers for the current thread keep ticking over. - * - * @return the number of milliseconds actually spent spinning which is guaranteed to be >= - * {@code ms} - */ - private static long spin(long ms) { - long start = threadMXBean.getCurrentThreadCpuTime(); - do { - long durationMS = (threadMXBean.getCurrentThreadCpuTime() - start) / 1000; - if (durationMS >= ms) { - return durationMS; - } - } while (true); - } - - @Test - public void test1() { - DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); - try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { - - DebugTimer timerA = Debug.timer("TimerA"); - DebugTimer timerB = Debug.timer("TimerB"); - - long spinA; - long spinB; - - try (DebugCloseable a1 = timerA.start()) { - spinA = spin(50); - try (DebugCloseable b1 = timerB.start()) { - spinB = spin(50); - } - } - - Assert.assertTrue(timerB.getCurrentValue() < timerA.getCurrentValue()); - if (timerA.getFlat() != null && timerB.getFlat() != null) { - assertTrue(spinB >= spinA || timerB.getFlat().getCurrentValue() < timerA.getFlat().getCurrentValue()); - assertEquals(timerA.getFlat().getCurrentValue(), timerA.getCurrentValue() - timerB.getFlat().getCurrentValue(), 10D); - } - } - } - - @Test - public void test2() { - DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); - try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { - DebugTimer timerC = Debug.timer("TimerC"); - try (DebugCloseable c1 = timerC.start()) { - spin(50); - try (DebugCloseable c2 = timerC.start()) { - spin(50); - try (DebugCloseable c3 = timerC.start()) { - spin(50); - try (DebugCloseable c4 = timerC.start()) { - spin(50); - try (DebugCloseable c5 = timerC.start()) { - spin(50); - } - } - } - } - } - if (timerC.getFlat() != null) { - assertEquals(timerC.getFlat().getCurrentValue(), timerC.getCurrentValue()); - } - } - } - - @Test - public void test3() { - DebugConfig debugConfig = Debug.fixedConfig(0, 0, false, false, true, false, null, null, System.out); - try (DebugConfigScope dcs = new DebugConfigScope(debugConfig); Debug.Scope s = Debug.scope("DebugTimerTest")) { - - DebugTimer timerD = Debug.timer("TimerD"); - DebugTimer timerE = Debug.timer("TimerE"); - - long spinD1; - long spinE; - - try (DebugCloseable d1 = timerD.start()) { - spinD1 = spin(50); - try (DebugCloseable e1 = timerE.start()) { - spinE = spin(50); - try (DebugCloseable d2 = timerD.start()) { - spin(50); - try (DebugCloseable d3 = timerD.start()) { - spin(50); - } - } - } - } - - Assert.assertTrue(timerE.getCurrentValue() < timerD.getCurrentValue()); - if (timerD.getFlat() != null && timerE.getFlat() != null) { - assertTrue(spinE >= spinD1 || timerE.getFlat().getCurrentValue() < timerD.getFlat().getCurrentValue()); - assertEquals(timerD.getFlat().getCurrentValue(), timerD.getCurrentValue() - timerE.getFlat().getCurrentValue(), 10D); - } - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/overview.html --- a/graal/com.oracle.graal.debug/overview.html Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ - - - - - - - - -Documentation for the com.oracle.graal.debug project. - - - diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/AnsiColor.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/AnsiColor.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * Ansi terminal color escape codes. - */ -public final class AnsiColor { - /** Foreground black. */ - public static final String BLACK = "\u001b[30m"; - /** Foreground red. */ - public static final String RED = "\u001b[31m"; - /** Foreground green. */ - public static final String GREEN = "\u001b[32m"; - /** Foreground yellow. */ - public static final String YELLOW = "\u001b[33m"; - /** Foreground blue. */ - public static final String BLUE = "\u001b[34m"; - /** Foreground magenta. */ - public static final String MAGENTA = "\u001b[35m"; - /** Foreground cyan. */ - public static final String CYAN = "\u001b[36m"; - /** Foreground white. */ - public static final String WHITE = "\u001b[37m"; - - /** Foreground bold black. */ - public static final String BOLD_BLACK = "\u001b[30;1m"; - /** Foreground bold red. */ - public static final String BOLD_RED = "\u001b[31;1m"; - /** Foreground bold green. */ - public static final String BOLD_GREEN = "\u001b[32;1m"; - /** Foreground bold yellow. */ - public static final String BOLD_YELLOW = "\u001b[33;1m"; - /** Foreground bold blue. */ - public static final String BOLD_BLUE = "\u001b[34;1m"; - /** Foreground bold magenta. */ - public static final String BOLD_MAGENTA = "\u001b[35;1m"; - /** Foreground bold cyan. */ - public static final String BOLD_CYAN = "\u001b[36;1m"; - /** Foreground bold white. */ - public static final String BOLD_WHITE = "\u001b[37;1m"; - - /** Background black. */ - public static final String BG_BLACK = "\u001b[40m"; - /** Background red. */ - public static final String BG_RED = "\u001b[41m"; - /** Background green. */ - public static final String BG_GREEN = "\u001b[42m"; - /** Background yellow. */ - public static final String BG_YELLOW = "\u001b[43m"; - /** Background blue. */ - public static final String BG_BLUE = "\u001b[44m"; - /** Background magenta. */ - public static final String BG_MAGENTA = "\u001b[45m"; - /** Background cyan. */ - public static final String BG_CYAN = "\u001b[46m"; - /** Background white. */ - public static final String BG_WHITE = "\u001b[47m"; - - /** Reset. */ - public static final String RESET = "\u001b[0m"; - /** Underline. */ - public static final String UNDERLINED = "\u001b[4m"; - - /** Prevent instantiation. */ - private AnsiColor() { - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Debug.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1551 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import static java.util.FormattableFlags.*; -import static com.oracle.graal.debug.Debug.Initialization.*; -import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import com.oracle.graal.debug.DelegatingDebugConfig.*; -import com.oracle.graal.debug.internal.*; -import jdk.internal.jvmci.service.*; - -/** - * Scope based debugging facility. This facility is {@link #isEnabled()} if assertions are enabled - * for the {@link Debug} class or the {@value Initialization#INITIALIZER_PROPERTY_NAME} system - * property is {@code "true"} when {@link Debug} is initialized. - */ -public class Debug { - - static { - for (DebugInitializationPropertyProvider p : Services.load(DebugInitializationPropertyProvider.class)) { - p.apply(); - } - } - - /** - * Class to assist with initialization of {@link Debug}. - */ - public static class Initialization { - - public static final String INITIALIZER_PROPERTY_NAME = "jvmci.debug.enable"; - - private static boolean initialized; - - /** - * Determines if {@link Debug} has been initialized. - */ - public static boolean isDebugInitialized() { - return initialized; - } - - } - - @SuppressWarnings("all") - private static boolean initialize() { - boolean assertionsEnabled = false; - assert assertionsEnabled = true; - Initialization.initialized = true; - return assertionsEnabled || Boolean.getBoolean(INITIALIZER_PROPERTY_NAME); - } - - private static final boolean ENABLED = initialize(); - - public static boolean isEnabled() { - return ENABLED; - } - - public static boolean isDumpEnabledForMethod() { - if (!ENABLED) { - return false; - } - DebugConfig config = DebugScope.getConfig(); - if (config == null) { - return false; - } - return config.isDumpEnabledForMethod(); - } - - public static final int DEFAULT_LOG_LEVEL = 2; - - public static boolean isDumpEnabled() { - return isDumpEnabled(DEFAULT_LOG_LEVEL); - } - - public static boolean isDumpEnabled(int dumpLevel) { - return ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel); - } - - /** - * Determines if verification is enabled in the current method, regardless of the - * {@linkplain Debug#currentScope() current debug scope}. - * - * @see Debug#verify(Object, String) - */ - public static boolean isVerifyEnabledForMethod() { - if (!ENABLED) { - return false; - } - DebugConfig config = DebugScope.getConfig(); - if (config == null) { - return false; - } - return config.isVerifyEnabledForMethod(); - } - - /** - * Determines if verification is enabled in the {@linkplain Debug#currentScope() current debug - * scope}. - * - * @see Debug#verify(Object, String) - */ - public static boolean isVerifyEnabled() { - return ENABLED && DebugScope.getInstance().isVerifyEnabled(); - } - - public static boolean isMeterEnabled() { - return ENABLED && DebugScope.getInstance().isMeterEnabled(); - } - - public static boolean isTimeEnabled() { - return ENABLED && DebugScope.getInstance().isTimeEnabled(); - } - - public static boolean isMemUseTrackingEnabled() { - return ENABLED && DebugScope.getInstance().isMemUseTrackingEnabled(); - } - - public static boolean isLogEnabledForMethod() { - if (!ENABLED) { - return false; - } - DebugConfig config = DebugScope.getConfig(); - if (config == null) { - return false; - } - return config.isLogEnabledForMethod(); - } - - public static boolean isLogEnabled() { - return isLogEnabled(DEFAULT_LOG_LEVEL); - } - - public static boolean isLogEnabled(int logLevel) { - return ENABLED && DebugScope.getInstance().isLogEnabled(logLevel); - } - - @SuppressWarnings("unused") - public static Runnable decorateDebugRoot(Runnable runnable, String name, DebugConfig config) { - return runnable; - } - - @SuppressWarnings("unused") - public static Callable decorateDebugRoot(Callable callable, String name, DebugConfig config) { - return callable; - } - - @SuppressWarnings("unused") - public static Runnable decorateScope(Runnable runnable, String name, Object... context) { - return runnable; - } - - @SuppressWarnings("unused") - public static Callable decorateScope(Callable callable, String name, Object... context) { - return callable; - } - - /** - * Gets a string composed of the names in the current nesting of debug - * {@linkplain #scope(Object) scopes} separated by {@code '.'}. - */ - public static String currentScope() { - if (ENABLED) { - return DebugScope.getInstance().getQualifiedName(); - } else { - return ""; - } - } - - /** - * Represents a debug scope entered by {@link Debug#scope(Object)} or - * {@link Debug#sandbox(CharSequence, DebugConfig, Object...)}. Leaving the scope is achieved - * via {@link #close()}. - */ - public interface Scope extends AutoCloseable { - void close(); - } - - /** - * Creates and enters a new debug scope which will be a child of the current debug scope. - *

- * It is recommended to use the try-with-resource statement for managing entering and leaving - * debug scopes. For example: - * - *

-     * try (Scope s = Debug.scope("InliningGraph", inlineeGraph)) {
-     *     ...
-     * } catch (Throwable e) {
-     *     throw Debug.handle(e);
-     * }
-     * 
- * - * The {@code name} argument is subject to the following type based conversion before having - * {@link Object#toString()} called on it: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @param name the name of the new scope - * @param contextObjects an array of object to be appended to the {@linkplain #context() - * current} debug context - * @throws Throwable used to enforce a catch block. - * @return the scope entered by this method which will be exited when its {@link Scope#close()} - * method is called - */ - public static Scope scope(Object name, Object[] contextObjects) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, contextObjects); - } else { - return null; - } - } - - /** - * Similar to {@link #scope(Object, Object[])} but without context objects. Therefore the catch - * block can be omitted. - * - * @see #scope(Object, Object[]) - */ - public static Scope scope(Object name) { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null); - } else { - return null; - } - } - - /** - * @see #scope(Object, Object[]) - * @param context an object to be appended to the {@linkplain #context() current} debug context - */ - public static Scope scope(Object name, Object context) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context); - } else { - return null; - } - } - - /** - * @see #scope(Object, Object[]) - * @param context1 first object to be appended to the {@linkplain #context() current} debug - * context - * @param context2 second object to be appended to the {@linkplain #context() current} debug - * context - */ - public static Scope scope(Object name, Object context1, Object context2) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context1, context2); - } else { - return null; - } - } - - /** - * @see #scope(Object, Object[]) - * @param context1 first object to be appended to the {@linkplain #context() current} debug - * context - * @param context2 second object to be appended to the {@linkplain #context() current} debug - * context - * @param context3 third object to be appended to the {@linkplain #context() current} debug - * context - */ - public static Scope scope(Object name, Object context1, Object context2, Object context3) throws Throwable { - if (ENABLED) { - return DebugScope.getInstance().scope(convertFormatArg(name).toString(), null, context1, context2, context3); - } else { - return null; - } - } - - /** - * Creates and enters a new debug scope which will be disjoint from the current debug scope. - *

- * It is recommended to use the try-with-resource statement for managing entering and leaving - * debug scopes. For example: - * - *

-     * try (Scope s = Debug.sandbox("CompilingStub", null, stubGraph)) {
-     *     ...
-     * } catch (Throwable e) {
-     *     throw Debug.handle(e);
-     * }
-     * 
- * - * @param name the name of the new scope - * @param config the debug configuration to use for the new scope - * @param context objects to be appended to the {@linkplain #context() current} debug context - * @return the scope entered by this method which will be exited when its {@link Scope#close()} - * method is called - */ - public static Scope sandbox(CharSequence name, DebugConfig config, Object... context) throws Throwable { - if (ENABLED) { - DebugConfig sandboxConfig = config == null ? silentConfig() : config; - return DebugScope.getInstance().scope(name, sandboxConfig, context); - } else { - return null; - } - } - - public static Scope forceLog() throws Throwable { - ArrayList context = new ArrayList<>(); - for (Object obj : context()) { - context.add(obj); - } - return Debug.sandbox("forceLog", new DelegatingDebugConfig().override(Level.LOG, Integer.MAX_VALUE).enable(LOG_METHOD), context.toArray()); - } - - /** - * Opens a scope in which exception {@linkplain DebugConfig#interceptException(Throwable) - * interception} is disabled. It is recommended to use the try-with-resource statement for - * managing entering and leaving such scopes: - * - *
-     * try (DebugConfigScope s = Debug.disableIntercept()) {
-     *     ...
-     * }
-     * 
- * - * This is particularly useful to suppress extraneous output in JUnit tests that are expected to - * throw an exception. - */ - public static DebugConfigScope disableIntercept() { - return Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT)); - } - - /** - * Handles an exception in the context of the debug scope just exited. The just exited scope - * must have the current scope as its parent which will be the case if the try-with-resource - * pattern recommended by {@link #scope(Object)} and - * {@link #sandbox(CharSequence, DebugConfig, Object...)} is used - * - * @see #scope(Object, Object[]) - * @see #sandbox(CharSequence, DebugConfig, Object...) - */ - public static RuntimeException handle(Throwable exception) { - if (ENABLED) { - return DebugScope.getInstance().handle(exception); - } else { - if (exception instanceof Error) { - throw (Error) exception; - } - if (exception instanceof RuntimeException) { - throw (RuntimeException) exception; - } - throw new RuntimeException(exception); - } - } - - public static void log(String msg) { - log(DEFAULT_LOG_LEVEL, msg); - } - - /** - * Prints a message to the current debug scope's logging stream if logging is enabled. - * - * @param msg the message to log - */ - public static void log(int logLevel, String msg) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, msg); - } - } - - public static void log(String format, Object arg) { - log(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * Prints a message to the current debug scope's logging stream if logging is enabled. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - */ - public static void log(int logLevel, String format, Object arg) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg); - } - } - - public static void log(String format, int arg) { - log(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * Prints a message to the current debug scope's logging stream if logging is enabled. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - */ - public static void log(int logLevel, String format, int arg) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg); - } - } - - public static void log(String format, Object arg1, Object arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, int arg1, Object arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, int arg1, Object arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, Object arg1, int arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, int arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, int arg1, int arg2) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, int arg1, int arg2) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3); - } - } - - public static void log(String format, int arg1, int arg2, int arg3) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, int arg1, int arg2, int arg3) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } - - public static void log(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) { - log(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } - - /** - * @see #log(int, String, Object) - */ - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } - } - - public static void log(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7, Object arg8) { - if (ENABLED) { - DebugScope.getInstance().log(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } - } - - public static void logv(String format, Object... args) { - logv(DEFAULT_LOG_LEVEL, format, args); - } - - /** - * Prints a message to the current debug scope's logging stream. This method must only be called - * if debugging is {@linkplain Debug#isEnabled() enabled} as it incurs allocation at the call - * site. If possible, call one of the other {@code log()} methods in this class that take a - * fixed number of parameters. - * - * @param format a format string - * @param args the arguments referenced by the format specifiers in {@code format} - */ - public static void logv(int logLevel, String format, Object... args) { - if (!ENABLED) { - throw new InternalError("Use of Debug.logv() must be guarded by a test of Debug.isEnabled()"); - } - DebugScope.getInstance().log(logLevel, format, args); - } - - /** - * This override exists to catch cases when {@link #log(String, Object)} is called with one - * argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void log(String format, Object[] args) { - assert false : "shouldn't use this"; - log(DEFAULT_LOG_LEVEL, format, args); - } - - /** - * This override exists to catch cases when {@link #log(int, String, Object)} is called with one - * argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void log(int logLevel, String format, Object[] args) { - assert false : "shouldn't use this"; - logv(logLevel, format, args); - } - - public static void dump(Object object, String msg) { - dump(DEFAULT_LOG_LEVEL, object, msg); - } - - public static void dump(int dumpLevel, Object object, String msg) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, msg); - } - } - - public static void dump(Object object, String format, Object arg) { - dump(DEFAULT_LOG_LEVEL, object, format, arg); - } - - public static void dump(int dumpLevel, Object object, String format, Object arg) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, arg); - } - } - - public static void dump(Object object, String format, Object arg1, Object arg2) { - dump(DEFAULT_LOG_LEVEL, object, format, arg1, arg2); - } - - public static void dump(int dumpLevel, Object object, String format, Object arg1, Object arg2) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, arg1, arg2); - } - } - - public static void dump(Object object, String format, Object arg1, Object arg2, Object arg3) { - dump(DEFAULT_LOG_LEVEL, object, format, arg1, arg2, arg3); - } - - public static void dump(int dumpLevel, Object object, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, arg1, arg2, arg3); - } - } - - /** - * This override exists to catch cases when {@link #dump(Object, String, Object)} is called with - * one argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void dump(Object object, String format, Object[] args) { - assert false : "shouldn't use this"; - dump(DEFAULT_LOG_LEVEL, object, format, args); - } - - /** - * This override exists to catch cases when {@link #dump(int, Object, String, Object)} is called - * with one argument bound to a varargs method parameter. It will bind to this method instead of - * the single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void dump(int dumpLevel, Object object, String format, Object[] args) { - assert false : "shouldn't use this"; - if (ENABLED && DebugScope.getInstance().isDumpEnabled(dumpLevel)) { - DebugScope.getInstance().dump(dumpLevel, object, format, args); - } - } - - /** - * Calls all {@link DebugVerifyHandler}s in the current {@linkplain DebugScope#getConfig() - * config} to perform verification on a given object. - * - * @param object object to verify - * @param message description of verification context - * - * @see DebugVerifyHandler#verify(Object, String) - */ - public static void verify(Object object, String message) { - if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { - DebugScope.getInstance().verify(object, message); - } - } - - /** - * Calls all {@link DebugVerifyHandler}s in the current {@linkplain DebugScope#getConfig() - * config} to perform verification on a given object. - * - * @param object object to verify - * @param format a format string for the description of the verification context - * @param arg the argument referenced by the format specifiers in {@code format} - * - * @see DebugVerifyHandler#verify(Object, String) - */ - public static void verify(Object object, String format, Object arg) { - if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { - DebugScope.getInstance().verify(object, format, arg); - } - } - - /** - * This override exists to catch cases when {@link #verify(Object, String, Object)} is called - * with one argument bound to a varargs method parameter. It will bind to this method instead of - * the single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void verify(Object object, String format, Object[] args) { - assert false : "shouldn't use this"; - if (ENABLED && DebugScope.getInstance().isVerifyEnabled()) { - DebugScope.getInstance().verify(object, format, args); - } - } - - /** - * Opens a new indentation level (by adding some spaces) based on the current indentation level. - * This should be used in a {@linkplain Indent try-with-resources} pattern. - * - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - * @see #logAndIndent(int, String) - * @see #logAndIndent(int, String, Object) - */ - public static Indent indent() { - if (ENABLED) { - DebugScope scope = DebugScope.getInstance(); - return scope.pushIndentLogger(); - } - return null; - } - - public static Indent logAndIndent(String msg) { - return logAndIndent(DEFAULT_LOG_LEVEL, msg); - } - - /** - * A convenience function which combines {@link #log(String)} and {@link #indent()}. - * - * @param msg the message to log - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logAndIndent(int logLevel, String msg) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, msg); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * A convenience function which combines {@link #log(String, Object)} and {@link #indent()}. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logAndIndent(int logLevel, String format, Object arg) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg); - } - return null; - } - - public static Indent logAndIndent(String format, int arg) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg); - } - - /** - * A convenience function which combines {@link #log(String, Object)} and {@link #indent()}. - * - * @param format a format string - * @param arg the argument referenced by the format specifiers in {@code format} - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logAndIndent(int logLevel, String format, int arg) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg); - } - return null; - } - - public static Indent logAndIndent(String format, int arg1, Object arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, int arg1, Object arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, int arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, int arg1, int arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); - } - return null; - } - - public static Indent logAndIndent(String format, int arg1, int arg2, int arg3) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, int arg1, int arg2, int arg3) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, int arg2, int arg3) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, int arg2, int arg3) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5); - } - return null; - } - - public static Indent logAndIndent(String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - return logAndIndent(DEFAULT_LOG_LEVEL, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - - /** - * @see #logAndIndent(int, String, Object) - */ - public static Indent logAndIndent(int logLevel, String format, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { - if (ENABLED && Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, arg1, arg2, arg3, arg4, arg5, arg6); - } - return null; - } - - /** - * A convenience function which combines {@link #logv(int, String, Object...)} and - * {@link #indent()}. - * - * @param format a format string - * @param args the arguments referenced by the format specifiers in {@code format} - * @return an object that reverts to the current indentation level when - * {@linkplain Indent#close() closed} or null if debugging is disabled - */ - public static Indent logvAndIndent(int logLevel, String format, Object... args) { - if (ENABLED) { - if (Debug.isLogEnabled(logLevel)) { - return logvAndIndentInternal(logLevel, format, args); - } - return null; - } - throw new InternalError("Use of Debug.logvAndIndent() must be guarded by a test of Debug.isEnabled()"); - } - - private static Indent logvAndIndentInternal(int logLevel, String format, Object... args) { - assert ENABLED && Debug.isLogEnabled(logLevel) : "must have checked Debug.isLogEnabled()"; - DebugScope scope = DebugScope.getInstance(); - scope.log(logLevel, format, args); - return scope.pushIndentLogger(); - } - - /** - * This override exists to catch cases when {@link #logAndIndent(String, Object)} is called with - * one argument bound to a varargs method parameter. It will bind to this method instead of the - * single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void logAndIndent(String format, Object[] args) { - assert false : "shouldn't use this"; - logAndIndent(DEFAULT_LOG_LEVEL, format, args); - } - - /** - * This override exists to catch cases when {@link #logAndIndent(int, String, Object)} is called - * with one argument bound to a varargs method parameter. It will bind to this method instead of - * the single arg variant and produce a deprecation warning instead of silently wrapping the - * Object[] inside of another Object[]. - */ - @Deprecated - public static void logAndIndent(int logLevel, String format, Object[] args) { - assert false : "shouldn't use this"; - logvAndIndent(logLevel, format, args); - } - - public static Iterable context() { - if (ENABLED) { - return DebugScope.getInstance().getCurrentContext(); - } else { - return Collections.emptyList(); - } - } - - @SuppressWarnings("unchecked") - public static List contextSnapshot(Class clazz) { - if (ENABLED) { - List result = new ArrayList<>(); - for (Object o : context()) { - if (clazz.isInstance(o)) { - result.add((T) o); - } - } - return result; - } else { - return Collections.emptyList(); - } - } - - /** - * Searches the current debug scope, bottom up, for a context object that is an instance of a - * given type. The first such object found is returned. - */ - @SuppressWarnings("unchecked") - public static T contextLookup(Class clazz) { - if (ENABLED) { - for (Object o : context()) { - if (clazz.isInstance(o)) { - return ((T) o); - } - } - } - return null; - } - - /** - * Creates a {@linkplain DebugMemUseTracker memory use tracker} that is enabled iff debugging is - * {@linkplain #isEnabled() enabled}. - *

- * A disabled tracker has virtually no overhead. - */ - public static DebugMemUseTracker memUseTracker(CharSequence name) { - if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { - return VOID_MEM_USE_TRACKER; - } - return createMemUseTracker("%s", name, null); - } - - /** - * Creates a debug memory use tracker. Invoking this method is equivalent to: - * - *

-     * Debug.memUseTracker(format, arg, null)
-     * 
- * - * except that the string formatting only happens if metering is enabled. - * - * @see #metric(String, Object, Object) - */ - public static DebugMemUseTracker memUseTracker(String format, Object arg) { - if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { - return VOID_MEM_USE_TRACKER; - } - return createMemUseTracker(format, arg, null); - } - - /** - * Creates a debug memory use tracker. Invoking this method is equivalent to: - * - *
-     * Debug.memUseTracker(String.format(format, arg1, arg2))
-     * 
- * - * except that the string formatting only happens if memory use tracking is enabled. In - * addition, each argument is subject to the following type based conversion before being passed - * as an argument to {@link String#format(String, Object...)}: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @see #memUseTracker(CharSequence) - */ - public static DebugMemUseTracker memUseTracker(String format, Object arg1, Object arg2) { - if (!isUnconditionalMemUseTrackingEnabled && !ENABLED) { - return VOID_MEM_USE_TRACKER; - } - return createMemUseTracker(format, arg1, arg2); - } - - private static DebugMemUseTracker createMemUseTracker(String format, Object arg1, Object arg2) { - String name = formatDebugName(format, arg1, arg2); - return new MemUseTrackerImpl(name, !isUnconditionalMemUseTrackingEnabled); - } - - /** - * Creates a {@linkplain DebugMetric metric} that is enabled iff debugging is - * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to - * {@value #ENABLE_METRIC_PROPERTY_NAME_PREFIX} to {@code name} is - * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the - * returned metric is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is - * conditional. - *

- * A disabled metric has virtually no overhead. - */ - public static DebugMetric metric(CharSequence name) { - if (!areUnconditionalMetricsEnabled() && !ENABLED) { - return VOID_METRIC; - } - return createMetric("%s", name, null); - } - - public static String applyFormattingFlagsAndWidth(String s, int flags, int width) { - if (flags == 0 && width < 0) { - return s; - } - StringBuilder sb = new StringBuilder(s); - - // apply width and justification - int len = sb.length(); - if (len < width) { - for (int i = 0; i < width - len; i++) { - if ((flags & LEFT_JUSTIFY) == LEFT_JUSTIFY) { - sb.append(' '); - } else { - sb.insert(0, ' '); - } - } - } - - String res = sb.toString(); - if ((flags & UPPERCASE) == UPPERCASE) { - res = res.toUpperCase(); - } - return res; - } - - /** - * Creates a debug metric. Invoking this method is equivalent to: - * - *

-     * Debug.metric(format, arg, null)
-     * 
- * - * except that the string formatting only happens if metering is enabled. - * - * @see #metric(String, Object, Object) - */ - public static DebugMetric metric(String format, Object arg) { - if (!areUnconditionalMetricsEnabled() && !ENABLED) { - return VOID_METRIC; - } - return createMetric(format, arg, null); - } - - /** - * Creates a debug metric. Invoking this method is equivalent to: - * - *
-     * Debug.metric(String.format(format, arg1, arg2))
-     * 
- * - * except that the string formatting only happens if metering is enabled. In addition, each - * argument is subject to the following type based conversion before being passed as an argument - * to {@link String#format(String, Object...)}: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @see #metric(CharSequence) - */ - public static DebugMetric metric(String format, Object arg1, Object arg2) { - if (!areUnconditionalMetricsEnabled() && !ENABLED) { - return VOID_METRIC; - } - return createMetric(format, arg1, arg2); - } - - private static DebugMetric createMetric(String format, Object arg1, Object arg2) { - String name = formatDebugName(format, arg1, arg2); - boolean conditional = enabledMetrics == null || !findMatch(enabledMetrics, enabledMetricsSubstrings, name); - if (!ENABLED && conditional) { - return VOID_METRIC; - } - return new MetricImpl(name, conditional); - } - - /** - * Changes the debug configuration for the current thread. - * - * @param config new configuration to use for the current thread - * @return an object that when {@linkplain DebugConfigScope#close() closed} will restore the - * debug configuration for the current thread to what it was before this method was - * called - */ - public static DebugConfigScope setConfig(DebugConfig config) { - if (ENABLED) { - return new DebugConfigScope(config); - } else { - return null; - } - } - - /** - * Creates an object for counting value frequencies. - */ - public static DebugHistogram createHistogram(String name) { - return new DebugHistogramImpl(name); - } - - public static DebugConfig silentConfig() { - return fixedConfig(0, 0, false, false, false, false, Collections. emptyList(), Collections. emptyList(), null); - } - - public static DebugConfig fixedConfig(final int logLevel, final int dumpLevel, final boolean isMeterEnabled, final boolean isMemUseTrackingEnabled, final boolean isTimerEnabled, - final boolean isVerifyEnabled, final Collection dumpHandlers, final Collection verifyHandlers, final PrintStream output) { - return new DebugConfig() { - - @Override - public int getLogLevel() { - return logLevel; - } - - public boolean isLogEnabledForMethod() { - return logLevel > 0; - } - - @Override - public boolean isMeterEnabled() { - return isMeterEnabled; - } - - @Override - public boolean isMemUseTrackingEnabled() { - return isMemUseTrackingEnabled; - } - - @Override - public int getDumpLevel() { - return dumpLevel; - } - - public boolean isDumpEnabledForMethod() { - return dumpLevel > 0; - } - - @Override - public boolean isVerifyEnabled() { - return isVerifyEnabled; - } - - public boolean isVerifyEnabledForMethod() { - return isVerifyEnabled; - } - - @Override - public boolean isTimeEnabled() { - return isTimerEnabled; - } - - @Override - public RuntimeException interceptException(Throwable e) { - return null; - } - - @Override - public Collection dumpHandlers() { - return dumpHandlers; - } - - @Override - public Collection verifyHandlers() { - return verifyHandlers; - } - - @Override - public PrintStream output() { - return output; - } - - @Override - public void addToContext(Object o) { - } - - @Override - public void removeFromContext(Object o) { - } - }; - } - - private static final DebugMetric VOID_METRIC = new DebugMetric() { - - public void increment() { - } - - public void add(long value) { - } - - public void setConditional(boolean flag) { - throw new InternalError("Cannot make void metric conditional"); - } - - public boolean isConditional() { - return false; - } - - public long getCurrentValue() { - return 0L; - } - }; - - private static final DebugMemUseTracker VOID_MEM_USE_TRACKER = new DebugMemUseTracker() { - - public DebugCloseable start() { - return DebugCloseable.VOID_CLOSEABLE; - } - - public long getCurrentValue() { - return 0; - } - }; - - public static final String ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME = "jvmci.debug.unscopedTimers"; - public static final String ENABLE_UNSCOPED_METRICS_PROPERTY_NAME = "jvmci.debug.unscopedMetrics"; - public static final String ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME = "jvmci.debug.unscopedMemUseTrackers"; - - /** - * @see #timer(CharSequence) - */ - public static final String ENABLE_TIMER_PROPERTY_NAME_PREFIX = "jvmci.debug.timer."; - - /** - * @see #metric(CharSequence) - */ - public static final String ENABLE_METRIC_PROPERTY_NAME_PREFIX = "jvmci.debug.metric."; - - /** - * Set of unconditionally enabled metrics. Possible values and their meanings: - *
    - *
  • {@code null}: no unconditionally enabled metrics
  • - *
  • {@code isEmpty()}: all metrics are unconditionally enabled
  • - *
  • {@code !isEmpty()}: use {@link #findMatch(Set, Set, String)} on this set and - * {@link #enabledMetricsSubstrings} to determine which metrics are unconditionally enabled
  • - *
- */ - private static final Set enabledMetrics; - - /** - * Set of unconditionally enabled timers. Same interpretation of values as for - * {@link #enabledMetrics}. - */ - private static final Set enabledTimers; - - private static final Set enabledMetricsSubstrings = new HashSet<>(); - private static final Set enabledTimersSubstrings = new HashSet<>(); - - /** - * Specifies if all mem use trackers are unconditionally enabled. - */ - private static final boolean isUnconditionalMemUseTrackingEnabled; - - static { - Set metrics = new HashSet<>(); - Set timers = new HashSet<>(); - parseMetricAndTimerSystemProperties(metrics, timers, enabledMetricsSubstrings, enabledTimersSubstrings); - metrics = metrics.isEmpty() && enabledMetricsSubstrings.isEmpty() ? null : metrics; - timers = timers.isEmpty() && enabledTimersSubstrings.isEmpty() ? null : timers; - if (metrics == null && Boolean.getBoolean(ENABLE_UNSCOPED_METRICS_PROPERTY_NAME)) { - metrics = Collections.emptySet(); - } - if (timers == null && Boolean.getBoolean(ENABLE_UNSCOPED_TIMERS_PROPERTY_NAME)) { - timers = Collections.emptySet(); - } - enabledMetrics = metrics; - enabledTimers = timers; - isUnconditionalMemUseTrackingEnabled = Boolean.getBoolean(ENABLE_UNSCOPED_MEM_USE_TRACKERS_PROPERTY_NAME); - } - - private static boolean findMatch(Set haystack, Set haystackSubstrings, String needle) { - if (haystack.isEmpty()) { - // Empty haystack means match all - return true; - } - if (haystack.contains(needle)) { - return true; - } - if (!haystackSubstrings.isEmpty()) { - for (String h : haystackSubstrings) { - if (needle.startsWith(h)) { - return true; - } - } - } - return false; - } - - public static boolean areUnconditionalTimersEnabled() { - return enabledTimers != null; - } - - public static boolean areUnconditionalMetricsEnabled() { - return enabledMetrics != null; - } - - protected static void parseMetricAndTimerSystemProperties(Set metrics, Set timers, Set metricsSubstrings, Set timersSubstrings) { - do { - try { - for (Map.Entry e : System.getProperties().entrySet()) { - String name = e.getKey().toString(); - if (name.startsWith(ENABLE_METRIC_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - if (name.endsWith("*")) { - metricsSubstrings.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); - } else { - metrics.add(name.substring(ENABLE_METRIC_PROPERTY_NAME_PREFIX.length())); - } - } - if (name.startsWith(ENABLE_TIMER_PROPERTY_NAME_PREFIX) && Boolean.parseBoolean(e.getValue().toString())) { - if (name.endsWith("*")) { - timersSubstrings.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length(), name.length() - 1)); - } else { - timers.add(name.substring(ENABLE_TIMER_PROPERTY_NAME_PREFIX.length())); - } - } - } - return; - } catch (ConcurrentModificationException e) { - // Iterating over the system properties may race with another thread that is - // updating the system properties. Simply try again in this case. - } - } while (true); - } - - /** - * Creates a {@linkplain DebugTimer timer} that is enabled iff debugging is - * {@linkplain #isEnabled() enabled} or the system property whose name is formed by adding to - * {@value #ENABLE_TIMER_PROPERTY_NAME_PREFIX} to {@code name} is - * {@linkplain Boolean#getBoolean(String) true}. If the latter condition is true, then the - * returned timer is {@linkplain DebugMetric#isConditional() unconditional} otherwise it is - * conditional. - *

- * A disabled timer has virtually no overhead. - */ - public static DebugTimer timer(CharSequence name) { - if (!areUnconditionalTimersEnabled() && !ENABLED) { - return VOID_TIMER; - } - return createTimer("%s", name, null); - } - - /** - * Creates a debug timer. Invoking this method is equivalent to: - * - *

-     * Debug.timer(format, arg, null)
-     * 
- * - * except that the string formatting only happens if timing is enabled. - * - * @see #timer(String, Object, Object) - */ - public static DebugTimer timer(String format, Object arg) { - if (!areUnconditionalTimersEnabled() && !ENABLED) { - return VOID_TIMER; - } - return createTimer(format, arg, null); - } - - /** - * Creates a debug timer. Invoking this method is equivalent to: - * - *
-     * Debug.timer(String.format(format, arg1, arg2))
-     * 
- * - * except that the string formatting only happens if timing is enabled. In addition, each - * argument is subject to the following type based conversion before being passed as an argument - * to {@link String#format(String, Object...)}: - * - *
-     *     Type          | Conversion
-     * ------------------+-----------------
-     *  java.lang.Class  | arg.getSimpleName()
-     *                   |
-     * 
- * - * @see #timer(CharSequence) - */ - public static DebugTimer timer(String format, Object arg1, Object arg2) { - if (!areUnconditionalTimersEnabled() && !ENABLED) { - return VOID_TIMER; - } - return createTimer(format, arg1, arg2); - } - - /** - * There are paths where construction of formatted class names are common and the code below is - * surprisingly expensive, so compute it once and cache it. - */ - private static final ClassValue formattedClassName = new ClassValue() { - @Override - protected String computeValue(Class c) { - final String simpleName = c.getSimpleName(); - Class enclosingClass = c.getEnclosingClass(); - if (enclosingClass != null) { - String prefix = ""; - while (enclosingClass != null) { - prefix = enclosingClass.getSimpleName() + "_" + prefix; - enclosingClass = enclosingClass.getEnclosingClass(); - } - return prefix + simpleName; - } else { - return simpleName; - } - } - }; - - public static Object convertFormatArg(Object arg) { - if (arg instanceof Class) { - return formattedClassName.get((Class) arg); - } - return arg; - } - - private static String formatDebugName(String format, Object arg1, Object arg2) { - return String.format(format, convertFormatArg(arg1), convertFormatArg(arg2)); - } - - private static DebugTimer createTimer(String format, Object arg1, Object arg2) { - String name = formatDebugName(format, arg1, arg2); - boolean conditional = enabledTimers == null || !findMatch(enabledTimers, enabledTimersSubstrings, name); - if (!ENABLED && conditional) { - return VOID_TIMER; - } - return new TimerImpl(name, conditional); - } - - private static final DebugTimer VOID_TIMER = new DebugTimer() { - - public DebugCloseable start() { - return DebugCloseable.VOID_CLOSEABLE; - } - - public void setConditional(boolean flag) { - throw new InternalError("Cannot make void timer conditional"); - } - - public boolean isConditional() { - return false; - } - - public long getCurrentValue() { - return 0L; - } - - public TimeUnit getTimeUnit() { - return null; - } - }; -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugCloseable.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugCloseable.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * An object returned by {@link DebugTimer#start()} that when closed, stops the associated timer and - * adds the elapsed time since {@code start()} to the total for the timer. - */ -public interface DebugCloseable extends AutoCloseable { - - DebugCloseable VOID_CLOSEABLE = new DebugCloseable() { - - @Override - public void close() { - } - }; - - void close(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfig.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.io.*; -import java.util.*; - -public interface DebugConfig { - - /** - * Determines the current log level in the {@linkplain Debug#currentScope() current debug scope} - * . - */ - int getLogLevel(); - - /** - * Determines the current dump level in the {@linkplain Debug#currentScope() current debug - * scope}. - */ - int getDumpLevel(); - - /** - * Determines if logging can be enabled in the current method, regardless of the - * {@linkplain Debug#currentScope() current debug scope}. - */ - boolean isLogEnabledForMethod(); - - /** - * Determines if metering is enabled in the {@linkplain Debug#currentScope() current debug - * scope}. - * - * @see Debug#metric(CharSequence) - */ - boolean isMeterEnabled(); - - /** - * Determines if memory use tracking is enabled in the {@linkplain Debug#currentScope() current - * debug scope}. - * - * @see Debug#memUseTracker(CharSequence) - */ - boolean isMemUseTrackingEnabled(); - - /** - * Determines if dumping can be enabled in the current method, regardless of the - * {@linkplain Debug#currentScope() current debug scope}. - */ - boolean isDumpEnabledForMethod(); - - /** - * @see Debug#isVerifyEnabled() - */ - boolean isVerifyEnabled(); - - /** - * @see Debug#isVerifyEnabledForMethod() - */ - boolean isVerifyEnabledForMethod(); - - /** - * Adds an object the context used by this configuration to do filtering. - */ - void addToContext(Object o); - - /** - * Removes an object the context used by this configuration to do filtering. - * - * This should only removes extra context added by {@link #addToContext(Object)}. - */ - void removeFromContext(Object o); - - /** - * @see Debug#timer(CharSequence) - */ - boolean isTimeEnabled(); - - /** - * Handles notification of an exception occurring within a debug scope. - * - * @return the exception object that is to be propagated to parent scope. A value of - * {@code null} indicates that {@code e} is to be propagated. - */ - RuntimeException interceptException(Throwable e); - - /** - * Gets the modifiable collection of dump handlers registered with this configuration. - */ - Collection dumpHandlers(); - - PrintStream output(); - - /** - * Gets the modifiable collection of verify handlers registered with this configuration. - */ - Collection verifyHandlers(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfigCustomizer.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfigCustomizer.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -public interface DebugConfigCustomizer { - void customize(DebugConfig config); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfigScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugConfigScope.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import com.oracle.graal.debug.internal.*; - -/** - * A utility for scoping a change to the current debug - * {@linkplain DebugScope#setConfig(DebugConfig) configuration}. For example: - * - *
- *     DebugConfig config = ...;
- *     try (DebugConfigScope s = new DebugConfigScope(config)) {
- *         // ...
- *     }
- * 
- */ -public class DebugConfigScope implements AutoCloseable { - - private final DebugConfig current; - - /** - * Sets the current debug {@linkplain DebugScope#setConfig(DebugConfig) configuration} to a - * given value and creates an object that when {@linkplain #close() closed} resets the - * configuration to the {@linkplain DebugScope#getConfig() current} configuration. - */ - public DebugConfigScope(DebugConfig config) { - this.current = DebugScope.getConfig(); - DebugScope.getInstance().setConfig(config); - } - - public void close() { - DebugScope.getInstance().setConfig(current); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpHandler.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.io.*; - -public interface DebugDumpHandler extends Closeable { - - void dump(Object object, String message); - - /** - * Flushes and releases resources managed by this dump handler. A subsequent call to - * {@link #dump(Object, String)} will create and open new resources. That is, this method can be - * used to reset the handler. - */ - @Override - void close(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -public class DebugDumpScope { - - public final String name; - - /** - * Specifies if this scope decorates an inner scope. A hierarchical or tree representation of - * nested scopes may choose to represent a decorator scope at the same level as the scope it - * decorates. - */ - public final boolean decorator; - - public DebugDumpScope(String name) { - this(name, false); - } - - public DebugDumpScope(String name, boolean decorator) { - this.name = name; - this.decorator = decorator; - } - - @Override - public String toString() { - return "DebugDumpScope[" + name + "]"; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugEnvironment.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugEnvironment.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import static com.oracle.graal.debug.JVMCIDebugConfig.*; - -import java.io.*; -import java.util.*; - -import jdk.internal.jvmci.service.*; - -public class DebugEnvironment { - - public static JVMCIDebugConfig initialize(PrintStream log) { - - if (!Debug.isEnabled()) { - log.println("WARNING: Scope debugging needs to be enabled with -esa or -D" + Debug.Initialization.INITIALIZER_PROPERTY_NAME + "=true"); - return null; - } - List dumpHandlers = new ArrayList<>(); - List verifyHandlers = new ArrayList<>(); - JVMCIDebugConfig debugConfig = new JVMCIDebugConfig(Log.getValue(), Meter.getValue(), TrackMemUse.getValue(), Time.getValue(), Dump.getValue(), Verify.getValue(), MethodFilter.getValue(), - log, dumpHandlers, verifyHandlers); - - for (DebugConfigCustomizer customizer : Services.load(DebugConfigCustomizer.class)) { - customizer.customize(debugConfig); - } - - Debug.setConfig(debugConfig); - return debugConfig; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugFilter.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugFilter.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.util.*; -import java.util.regex.*; - -import com.oracle.graal.debug.internal.*; - -/** - * Implements the filter specified by the {@link JVMCIDebugConfig#Dump}, - * {@link JVMCIDebugConfig#Log}, {@link JVMCIDebugConfig#Meter} and {@link JVMCIDebugConfig#Time} - * options. - *

- * These options enable the associated debug facility if their filter matches the - * {@linkplain DebugScope#getQualifiedName() name} of the {@linkplain Debug#currentScope() current - * scope}. For the {@link JVMCIDebugConfig#Dump} and {@link JVMCIDebugConfig#Log} options, the log - * or dump level is set. The {@link JVMCIDebugConfig#Meter} and {@link JVMCIDebugConfig#Time} - * options don't have a level, for them {@code level = 0} means disabled and a {@code level > 0} - * means enabled. - *

- * A filter is a list of comma-separated terms of the form {@code [:]}. - * {@code } is interpreted as a glob pattern if it contains a "*" or "?" character. - * Otherwise, it is interpreted as a substring. If {@code } is empty, it matches every - * scope. If {@code :} is omitted, it defaults to {@link Debug#DEFAULT_LOG_LEVEL}. The term - * {@code ~} is a shorthand for {@code :0} to disable a debug facility for a - * pattern. - *

- * The resulting log level of a scope is determined by the last matching term. If no term - * matches, the log level is 0 (disabled). A filter with no terms matches every scope with a log - * level of {@link Debug#DEFAULT_LOG_LEVEL}. - * - *

Examples of filters

- * - *
    - *
  • (empty string)
    - * Matches any scope with log level {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code :1}
    - * Matches any scope with log level 1. - * - *
  • {@code *}
    - * Matches any scope with log level {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code CodeGen,CodeInstall}
    - * Matches scopes containing "CodeGen" or "CodeInstall", both with log level - * {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code CodeGen:2,CodeInstall:1}
    - * Matches scopes containing "CodeGen" with log level 2, or "CodeInstall" with log level 1. - * - *
  • {@code :1,Dead:2}
    - * Matches scopes containing "Dead" with log level 2, and all other scopes with log level 1. - * - *
  • {@code :1,Dead:0}
    - * Matches all scopes with log level 1, except those containing "Dead". - * - *
  • {@code Code*}
    - * Matches scopes starting with "Code" with log level {@link Debug#DEFAULT_LOG_LEVEL}. - * - *
  • {@code Code,~Dead}
    - * Matches scopes containing "Code" but not "Dead", with log level {@link Debug#DEFAULT_LOG_LEVEL}. - *
- */ -final class DebugFilter { - - public static DebugFilter parse(String spec) { - if (spec == null) { - return null; - } - return new DebugFilter(spec.split(",")); - } - - private final Term[] terms; - - private DebugFilter(String[] terms) { - if (terms.length == 0) { - this.terms = null; - } else { - this.terms = new Term[terms.length]; - for (int i = 0; i < terms.length; i++) { - String t = terms[i]; - int idx = t.indexOf(':'); - - String pattern; - int level; - if (idx < 0) { - if (t.startsWith("~")) { - pattern = t.substring(1); - level = 0; - } else { - pattern = t; - level = Debug.DEFAULT_LOG_LEVEL; - } - } else { - pattern = t.substring(0, idx); - if (idx + 1 < t.length()) { - level = Integer.parseInt(t.substring(idx + 1)); - } else { - level = Debug.DEFAULT_LOG_LEVEL; - } - } - - this.terms[i] = new Term(pattern, level); - } - } - } - - /** - * Check whether a given input is matched by this filter, and determine the log level. - */ - public int matchLevel(String input) { - if (terms == null) { - return Debug.DEFAULT_LOG_LEVEL; - } else { - int level = 0; - for (Term t : terms) { - if (t.matches(input)) { - level = t.level; - } - } - return level; - } - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder("DebugFilter"); - if (terms != null) { - buf.append(Arrays.toString(terms)); - } else { - buf.append("[]"); - } - return buf.toString(); - } - - private static class Term { - - private final Pattern pattern; - public final int level; - - public Term(String filter, int level) { - this.level = level; - if (filter.isEmpty()) { - this.pattern = null; - } else if (filter.contains("*") || filter.contains("?")) { - this.pattern = Pattern.compile(MethodFilter.createGlobString(filter)); - } else { - this.pattern = Pattern.compile(".*" + MethodFilter.createGlobString(filter) + ".*"); - } - } - - /** - * Determines if a given input is matched by this filter. - */ - public boolean matches(String input) { - return pattern == null || pattern.matcher(input).matches(); - } - - @Override - public String toString() { - return (pattern == null ? ".*" : pattern.toString()) + ":" + level; - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugHistogram.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugHistogram.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.util.*; - -/** - * Facility for recording value frequencies. - */ -public interface DebugHistogram { - - /** - * Gets the name specified when this objected was {@linkplain Debug#createHistogram(String) - * created}. - */ - String getName(); - - /** - * Increments the count for a given value. - */ - void add(Object value); - - void add(Object value, long count); - - /** - * A value and a frequency. The ordering imposed by {@link #compareTo(CountedValue)} places - * values with higher frequencies first. - */ - public class CountedValue implements Comparable { - - private long count; - private final Object value; - - public CountedValue(long count, Object value) { - this.count = count; - this.value = value; - } - - public int compareTo(CountedValue o) { - if (count < o.count) { - return 1; - } else if (count > o.count) { - return -1; - } - return 0; - } - - @Override - public String toString() { - return count + " -> " + value; - } - - public void inc() { - count++; - } - - public void add(long n) { - count += n; - } - - public long getCount() { - return count; - } - - public Object getValue() { - return value; - } - } - - /** - * Gets a list of the counted values, sorted in descending order of frequency. - */ - List getValues(); - - /** - * Interface for a service that can render a visualization of a histogram. - */ - public interface Printer { - - void print(DebugHistogram histogram); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugInitializationPropertyProvider.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugInitializationPropertyProvider.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * Sets one or more system properties used during initialization of the {@link Debug} class. - */ -public interface DebugInitializationPropertyProvider { - void apply(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugMemUseTracker.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugMemUseTracker.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import com.sun.management.*; - -/** - * Tracks memory usage within a scope using {@link ThreadMXBean}. This facility should be employed - * using the try-with-resources pattern: - * - *
- * try (DebugMemUseTracker.Closeable a = memUseTracker.start()) {
- *     // the code to measure
- * }
- * 
- */ -public interface DebugMemUseTracker { - - /** - * Creates a point from which memory usage will be recorded if memory use tracking is - * {@linkplain Debug#isMemUseTrackingEnabled() enabled}. - * - * @return an object that must be closed once the activity has completed to add the memory used - * since this call to the total for this tracker - */ - DebugCloseable start(); - - /** - * Gets the current value of this tracker. - */ - long getCurrentValue(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugMetric.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugMetric.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * A counter for some value of interest. - */ -public interface DebugMetric { - - /** - * Adds 1 to this counter if metering is {@link Debug#isMeterEnabled() enabled} or this is an - * {@linkplain #isConditional() unconditional} metric. - */ - void increment(); - - /** - * Adds {@code value} to this counter if metering is {@link Debug#isMeterEnabled() enabled} or - * this is an {@linkplain #isConditional() unconditional} metric. - */ - void add(long value); - - /** - * Sets a flag determining if this counter is only enabled if metering is - * {@link Debug#isMeterEnabled() enabled}. - */ - void setConditional(boolean flag); - - /** - * Determines if this counter is only enabled if metering is {@link Debug#isMeterEnabled() - * enabled}. - */ - boolean isConditional(); - - /** - * Gets the current value of this metric. - */ - long getCurrentValue(); - - /** - * Determines if this counter is enabled (either conditionally or unconditionally). - */ - default boolean isEnabled() { - return !isConditional() || Debug.isMeterEnabled(); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugTimer.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugTimer.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.util.concurrent.*; - -/** - * A timer for some activity of interest. A timer should be deployed using the try-with-resources - * pattern: - * - *
- * try (TimerCloseable a = timer.start()) {
- *     // the code to time
- * }
- * 
- */ -public interface DebugTimer { - - /** - * Starts this timer if timing is {@linkplain Debug#isTimeEnabled() enabled} or this is an - * {@linkplain #isConditional() unconditional} timer. - * - * @return an object that must be closed once the activity has completed to add the elapsed time - * since this call to the total for this timer - */ - DebugCloseable start(); - - /** - * Sets a flag determining if this timer is only enabled if timing is - * {@link Debug#isTimeEnabled() enabled}. - */ - void setConditional(boolean flag); - - /** - * Determines if this timer is only enabled if timing is {@link Debug#isTimeEnabled() enabled}. - */ - boolean isConditional(); - - /** - * Gets the current value of this timer. - */ - long getCurrentValue(); - - /** - * Gets the time unit of this timer. - */ - TimeUnit getTimeUnit(); - - /** - * Gets the timer recording the amount time spent within a timed scope minus the time spent in - * any nested timed scopes. - * - * @return null if this timer does not support flat timing - */ - default DebugTimer getFlat() { - return null; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugVerifyHandler.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugVerifyHandler.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * Performs some kind of verification on an object. - */ -public interface DebugVerifyHandler { - - /** - * Verifies that a given object satisfies some invariants. - * - * @param object object to verify - * @param message description of verification context - */ - void verify(Object object, String message); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DelegatingDebugConfig.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DelegatingDebugConfig.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.io.*; -import java.util.*; - -import com.oracle.graal.debug.internal.*; - -public class DelegatingDebugConfig implements DebugConfig { - - protected final DebugConfig delegate; - - /** - * The features of a {@link DelegatingDebugConfig} that can be force - * {@linkplain DelegatingDebugConfig#enable(Feature) enabled}/ - * {@linkplain DelegatingDebugConfig#disable(Feature) disabled} or - * {@linkplain DelegatingDebugConfig#delegate(Feature) delegated}. - */ - public enum Feature { - /** - * @see Debug#isLogEnabledForMethod() - */ - LOG_METHOD, - /** - * @see Debug#isDumpEnabledForMethod() - */ - DUMP_METHOD, - /** - * @see Debug#isVerifyEnabled() - */ - VERIFY, - /** - * @see Debug#isVerifyEnabledForMethod() - */ - VERIFY_METHOD, - /** - * @see Debug#isMeterEnabled() - */ - METER, - /** - * @see Debug#isMemUseTrackingEnabled() - */ - TRACK_MEM_USE, - /** - * @see Debug#isTimeEnabled() - */ - TIME, - /** - * @see DebugConfig#interceptException(Throwable) - */ - INTERCEPT - } - - private final Map featureState = new EnumMap<>(Feature.class); - - /** - * The debug levels of a {@link DelegatingDebugConfig} than can be - * {@linkplain DelegatingDebugConfig#override(Level, int) overridden} or - * {@linkplain DelegatingDebugConfig#delegate(Level) delegated}. - */ - public enum Level { - LOG, - DUMP - } - - private final Map levelState = new EnumMap<>(Level.class); - - /** - * Creates a config that delegates to the {@link DebugScope#getConfig() current config}. - */ - public DelegatingDebugConfig() { - this(DebugScope.getConfig()); - } - - /** - * Creates a config that delegates to a given config. - */ - public DelegatingDebugConfig(DebugConfig delegate) { - this.delegate = delegate; - } - - public DelegatingDebugConfig enable(Feature feature) { - featureState.put(feature, Boolean.TRUE); - return this; - } - - public DelegatingDebugConfig disable(Feature feature) { - featureState.put(feature, Boolean.FALSE); - return this; - } - - public DelegatingDebugConfig override(Level level, int newLevel) { - levelState.put(level, newLevel); - return this; - } - - public DelegatingDebugConfig delegate(Feature feature) { - featureState.put(feature, null); - return this; - } - - public DelegatingDebugConfig delegate(Level level) { - levelState.put(level, null); - return this; - } - - @Override - public int getLogLevel() { - Integer ls = levelState.get(Level.LOG); - if (ls == null) { - return delegate.getLogLevel(); - } - return ls.intValue(); - } - - public boolean isLogEnabledForMethod() { - Boolean fs = featureState.get(Feature.LOG_METHOD); - if (fs == null) { - return delegate.isLogEnabledForMethod(); - } - return fs.booleanValue(); - } - - @Override - public boolean isMeterEnabled() { - Boolean fs = featureState.get(Feature.METER); - if (fs == null) { - return delegate.isMeterEnabled(); - } - return fs.booleanValue(); - } - - public boolean isMemUseTrackingEnabled() { - Boolean fs = featureState.get(Feature.TRACK_MEM_USE); - if (fs == null) { - return delegate.isMemUseTrackingEnabled(); - } - return fs.booleanValue(); - } - - @Override - public int getDumpLevel() { - Integer ls = levelState.get(Level.DUMP); - if (ls == null) { - return delegate.getDumpLevel(); - } - return ls.intValue(); - } - - public boolean isDumpEnabledForMethod() { - Boolean fs = featureState.get(Feature.DUMP_METHOD); - if (fs == null) { - return delegate.isDumpEnabledForMethod(); - } - return fs.booleanValue(); - } - - @Override - public boolean isVerifyEnabled() { - Boolean fs = featureState.get(Feature.VERIFY); - if (fs == null) { - return delegate.isVerifyEnabled(); - } - return fs.booleanValue(); - } - - public boolean isVerifyEnabledForMethod() { - Boolean fs = featureState.get(Feature.VERIFY_METHOD); - if (fs == null) { - return delegate.isVerifyEnabledForMethod(); - } - return fs.booleanValue(); - } - - @Override - public boolean isTimeEnabled() { - Boolean fs = featureState.get(Feature.TIME); - if (fs == null) { - return delegate.isTimeEnabled(); - } - return fs.booleanValue(); - } - - @Override - public RuntimeException interceptException(Throwable e) { - Boolean fs = featureState.get(Feature.INTERCEPT); - if (fs == null || fs) { - return delegate.interceptException(e); - } - return null; - } - - @Override - public Collection dumpHandlers() { - return delegate.dumpHandlers(); - } - - @Override - public Collection verifyHandlers() { - return delegate.verifyHandlers(); - } - - @Override - public PrintStream output() { - return delegate.output(); - } - - @Override - public void addToContext(Object o) { - delegate.addToContext(o); - } - - @Override - public void removeFromContext(Object o) { - delegate.removeFromContext(o); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Fingerprint.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Fingerprint.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.util.*; -import java.util.stream.*; - -/** - * Facility for fingerprinting execution. - */ -public class Fingerprint implements AutoCloseable { - - public static final String ENABLED_PROPERTY_NAME = "jvmci.fingerprint"; - - /** - * Determines whether fingerprinting is enabled. This is set by the - * {@value #ENABLED_PROPERTY_NAME} system property when this class is initialized. - */ - public static final boolean ENABLED = Boolean.getBoolean(ENABLED_PROPERTY_NAME); - - private static final ThreadLocal current = ENABLED ? new ThreadLocal<>() : null; - - private final List events; - private int index; - - /** - * Creates an object to record a fingerprint. - */ - public Fingerprint() { - events = new ArrayList<>(); - index = -1; - } - - /** - * Creates an object to verify execution matches a given fingerprint. - * - * @param toVerifyAgainst the fingerprint events to verify against - */ - public Fingerprint(List toVerifyAgainst) { - this.events = toVerifyAgainst; - index = 0; - } - - /** - * Creates an object to verify execution matches a given fingerprint. - * - * @param toVerifyAgainst the fingerprint to verify against - */ - public Fingerprint(Fingerprint toVerifyAgainst) { - this(toVerifyAgainst.events); - } - - public Collection getEvents() { - return Collections.unmodifiableCollection(events); - } - - /** - * Starts fingerprint recording or verification for the current thread. At most one fingerprint - * object can be active for any thread. - */ - public Fingerprint open() { - if (ENABLED) { - assert current.get() == null; - current.set(this); - return this; - } - return null; - } - - /** - * Finishes fingerprint recording or verification for the current thread. - */ - public void close() { - if (ENABLED) { - assert current.get() == this; - current.set(null); - } - } - - private static final int BREAKPOINT_EVENT = Integer.getInteger(ENABLED_PROPERTY_NAME + ".breakpointEvent", -1); - - /** - * Submits an execution event for the purpose of recording or verifying a fingerprint. This must - * only be called if {@link #ENABLED} is {@code true}. - */ - public static void submit(String format, Object... args) { - assert ENABLED : "fingerprinting must be enabled (-D" + ENABLED_PROPERTY_NAME + "=true)"; - Fingerprint fingerprint = current.get(); - if (fingerprint != null) { - int eventId = fingerprint.nextEventId(); - if (eventId == BREAKPOINT_EVENT) { - // Set IDE breakpoint on the following line and set the relevant - // system property to debug a fingerprint verification error. - System.console(); - } - fingerprint.event(String.format(eventId + ": " + format, args)); - } - } - - private int nextEventId() { - return index == -1 ? events.size() : index; - } - - private static final int MAX_EVENT_TAIL_IN_ERROR_MESSAGE = Integer.getInteger("jvmci.fingerprint.errorEventTailLength", 50); - - private String tail() { - int start = Math.max(index - MAX_EVENT_TAIL_IN_ERROR_MESSAGE, 0); - return events.subList(start, index).stream().collect(Collectors.joining(String.format("%n"))); - } - - private void event(String entry) { - if (index == -1) { - events.add(entry); - } else { - if (index > events.size()) { - throw new InternalError(String.format("%s%nOriginal fingerprint limit reached", tail())); - } - String l = events.get(index); - if (!l.equals(entry)) { - throw new InternalError(String.format("%s%nFingerprint differs at event %d%nexpected: %s%n actual: %s", tail(), index, l, entry)); - } - index++; - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Indent.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/Indent.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * Object used to close a debug {@link Debug#indent() indentation} scope. - *

- * Example usage: - * - *

- *
- *      try (Indent i1 = Debug.logAndIndent("header message")) {
- *          ...
- *          Debug.log("message");
- *          ...
- *          try (Indent i2 = Debug.logAndIndent(sub-header message")) {
- *              ...
- *              Debug.log("inner message");
- *              ...
- *          }
- *      }
- *
- * 
- */ -public interface Indent extends AutoCloseable { - - /** - * Closes the current indentation scope. - */ - void close(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/JVMCIDebugConfig.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/JVMCIDebugConfig.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.io.*; -import java.util.*; - -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.meta.*; -import jdk.internal.jvmci.options.*; - -public class JVMCIDebugConfig implements DebugConfig { - @SuppressWarnings("all") - private static boolean assertionsEnabled() { - boolean assertionsEnabled = false; - assert assertionsEnabled = true; - return assertionsEnabled; - } - - // @formatter:off - @Option(help = "Pattern for scope(s) in which dumping is enabled (see DebugFilter and Debug.dump)", type = OptionType.Debug) - public static final OptionValue Dump = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which metering is enabled (see DebugFilter and Debug.metric). " + - "An empty value enables all metrics unconditionally.", type = OptionType.Debug) - public static final OptionValue Meter = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which verification is enabled (see DebugFilter and Debug.verify).", type = OptionType.Debug) - public static final OptionValue Verify = new OptionValue() { - @Override - protected String defaultValue() { - return assertionsEnabled() ? "" : null; - } - }; - @Option(help = "Pattern for scope(s) in which memory use tracking is enabled (see DebugFilter and Debug.metric). " + - "An empty value enables all memory use trackers unconditionally.", type = OptionType.Debug) - public static final OptionValue TrackMemUse = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which timing is enabled (see DebugFilter and Debug.timer). " + - "An empty value enables all timers unconditionally.", type = OptionType.Debug) - public static final OptionValue Time = new OptionValue<>(null); - @Option(help = "Pattern for scope(s) in which logging is enabled (see DebugFilter and Debug.log)", type = OptionType.Debug) - public static final OptionValue Log = new OptionValue<>(null); - @Option(help = "Pattern for filtering debug scope output based on method context (see MethodFilter)", type = OptionType.Debug) - public static final OptionValue MethodFilter = new OptionValue<>(null); - @Option(help = "Only check MethodFilter against the root method in the context if true, otherwise check all methods", type = OptionType.Debug) - public static final OptionValue MethodFilterRootOnly = new OptionValue<>(false); - - @Option(help = "How to print metric and timing values:%n" + - "Name - aggregate by unqualified name%n" + - "Partial - aggregate by partially qualified name (e.g., A.B.C.D.Counter and X.Y.Z.D.Counter will be merged to D.Counter)%n" + - "Complete - aggregate by qualified name%n" + - "Thread - aggregate by qualified name and thread", type = OptionType.Debug) - public static final OptionValue DebugValueSummary = new OptionValue<>("Name"); - @Option(help = "Omit reporting 0-value metrics", type = OptionType.Debug) - public static final OptionValue SuppressZeroDebugValues = new OptionValue<>(true); - @Option(help = "Only report debug values for maps which match the regular expression.", type = OptionType.Debug) - public static final OptionValue DebugValueThreadFilter = new OptionValue<>(null); - @Option(help = "Send JVMCI compiler IR to dump handlers on error", type = OptionType.Debug) - public static final OptionValue DumpOnError = new OptionValue<>(false); - @Option(help = "Intercept also bailout exceptions", type = OptionType.Debug) - public static final OptionValue InterceptBailout = new OptionValue<>(false); - @Option(help = "Enable more verbose log output when available", type = OptionType.Debug) - public static final OptionValue LogVerbose = new OptionValue<>(false); - // @formatter:on - - static boolean isNotEmpty(OptionValue option) { - return option.getValue() != null && !option.getValue().isEmpty(); - } - - public static boolean areDebugScopePatternsEnabled() { - return DumpOnError.getValue() || Dump.getValue() != null || Log.getValue() != null || areScopedMetricsOrTimersEnabled(); - } - - /** - * Determines if any of {@link #Meter}, {@link #Time} or {@link #TrackMemUse} has a non-null, - * non-empty value. - */ - public static boolean areScopedMetricsOrTimersEnabled() { - return isNotEmpty(Meter) || isNotEmpty(Time) || isNotEmpty(TrackMemUse); - } - - private final DebugFilter logFilter; - private final DebugFilter meterFilter; - private final DebugFilter trackMemUseFilter; - private final DebugFilter timerFilter; - private final DebugFilter dumpFilter; - private final DebugFilter verifyFilter; - private final MethodFilter[] methodFilter; - private final List dumpHandlers; - private final List verifyHandlers; - private final PrintStream output; - private final Set extraFilters = new HashSet<>(); - - public JVMCIDebugConfig(String logFilter, String meterFilter, String trackMemUseFilter, String timerFilter, String dumpFilter, String verifyFilter, String methodFilter, PrintStream output, - List dumpHandlers, List verifyHandlers) { - this.logFilter = DebugFilter.parse(logFilter); - this.meterFilter = DebugFilter.parse(meterFilter); - this.trackMemUseFilter = DebugFilter.parse(trackMemUseFilter); - this.timerFilter = DebugFilter.parse(timerFilter); - this.dumpFilter = DebugFilter.parse(dumpFilter); - this.verifyFilter = DebugFilter.parse(verifyFilter); - if (methodFilter == null || methodFilter.isEmpty()) { - this.methodFilter = null; - } else { - this.methodFilter = com.oracle.graal.debug.MethodFilter.parse(methodFilter); - } - - // Report the filters that have been configured so the user can verify it's what they expect - if (logFilter != null || meterFilter != null || timerFilter != null || dumpFilter != null || methodFilter != null) { - // TTY.println(Thread.currentThread().getName() + ": " + toString()); - } - this.dumpHandlers = dumpHandlers; - this.verifyHandlers = verifyHandlers; - this.output = output; - } - - public int getLogLevel() { - return getLevel(logFilter); - } - - public boolean isLogEnabledForMethod() { - return isEnabledForMethod(logFilter); - } - - public boolean isMeterEnabled() { - return isEnabled(meterFilter); - } - - public boolean isMemUseTrackingEnabled() { - return isEnabled(trackMemUseFilter); - } - - public int getDumpLevel() { - return getLevel(dumpFilter); - } - - public boolean isDumpEnabledForMethod() { - return isEnabledForMethod(dumpFilter); - } - - public boolean isVerifyEnabled() { - return isEnabled(verifyFilter); - } - - public boolean isVerifyEnabledForMethod() { - return isEnabledForMethod(verifyFilter); - } - - public boolean isTimeEnabled() { - return isEnabled(timerFilter); - } - - public PrintStream output() { - return output; - } - - private boolean isEnabled(DebugFilter filter) { - return getLevel(filter) > 0; - } - - private int getLevel(DebugFilter filter) { - int level; - if (filter == null) { - level = 0; - } else { - level = filter.matchLevel(Debug.currentScope()); - } - if (level > 0 && !checkMethodFilter()) { - level = 0; - } - return level; - } - - private boolean isEnabledForMethod(DebugFilter filter) { - return filter != null && checkMethodFilter(); - } - - /** - * Extracts a {@link JavaMethod} from an opaque debug context. - * - * @return the {@link JavaMethod} represented by {@code context} or null - */ - public static JavaMethod asJavaMethod(Object context) { - if (context instanceof JavaMethodContex) { - return ((JavaMethodContex) context).asJavaMethod(); - } - return null; - } - - private boolean checkMethodFilter() { - if (methodFilter == null && extraFilters.isEmpty()) { - return true; - } else { - JavaMethod lastMethod = null; - for (Object o : Debug.context()) { - if (extraFilters.contains(o)) { - return true; - } else if (methodFilter != null) { - JavaMethod method = asJavaMethod(o); - if (method != null) { - if (!MethodFilterRootOnly.getValue()) { - if (com.oracle.graal.debug.MethodFilter.matches(methodFilter, method)) { - return true; - } - } else { - /* - * The context values operate as a stack so if we want MethodFilter to - * only apply to the root method we have to check only the last method - * seen. - */ - lastMethod = method; - } - } - } - } - if (lastMethod != null && com.oracle.graal.debug.MethodFilter.matches(methodFilter, lastMethod)) { - return true; - } - return false; - } - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("Debug config:"); - add(sb, "Log", logFilter); - add(sb, "Meter", meterFilter); - add(sb, "Time", timerFilter); - add(sb, "Dump", dumpFilter); - add(sb, "MethodFilter", methodFilter); - return sb.toString(); - } - - private static void add(StringBuilder sb, String name, Object filter) { - if (filter != null) { - sb.append(' '); - sb.append(name); - sb.append('='); - if (filter instanceof Object[]) { - sb.append(Arrays.toString((Object[]) filter)); - } else { - sb.append(String.valueOf(filter)); - } - } - } - - @Override - public RuntimeException interceptException(Throwable e) { - if (e instanceof BailoutException && !InterceptBailout.getValue()) { - return null; - } - Debug.setConfig(Debug.fixedConfig(Debug.DEFAULT_LOG_LEVEL, Debug.DEFAULT_LOG_LEVEL, false, false, false, false, dumpHandlers, verifyHandlers, output)); - Debug.log(String.format("Exception occurred in scope: %s", Debug.currentScope())); - for (Object o : Debug.context()) { - if (DumpOnError.getValue()) { - Debug.dump(o, "Exception: " + e.toString()); - } else { - Debug.log("Context obj %s", o); - } - - } - return null; - } - - @Override - public Collection dumpHandlers() { - return dumpHandlers; - } - - @Override - public Collection verifyHandlers() { - return verifyHandlers; - } - - @Override - public void addToContext(Object o) { - extraFilters.add(o); - } - - @Override - public void removeFromContext(Object o) { - extraFilters.remove(o); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/JavaMethodContex.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/JavaMethodContex.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import jdk.internal.jvmci.meta.*; - -/** - * Interface for objects used in Debug {@linkplain Debug#context() context} that can provide a - * {@link JavaMethod}. - */ -public interface JavaMethodContex { - JavaMethod asJavaMethod(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/MethodFilter.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/MethodFilter.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -import java.util.*; -import java.util.regex.*; - -import jdk.internal.jvmci.meta.*; - -/** - * This class implements a method filter that can filter based on class name, method name and - * parameters. The syntax for the source pattern that is passed to the constructor is as follows: - * - *
- * SourcePatterns = SourcePattern ["," SourcePatterns] .
- * SourcePattern = [ Class "." ] method [ "(" [ Parameter { ";" Parameter } ] ")" ] .
- * Parameter = Class | "int" | "long" | "float" | "double" | "short" | "char" | "boolean" .
- * Class = { package "." } class .
- * 
- * - * - * Glob pattern matching (*, ?) is allowed in all parts of the source pattern. Examples for valid - * filters are: - * - *
    - *
  • - * - *
    - * visit(Argument;BlockScope)
    - * 
    - * - * Matches all methods named "visit", with the first parameter of type "Argument", and the second - * parameter of type "BlockScope". The packages of the parameter types are irrelevant.
  • - *
  • - * - *
    - * arraycopy(Object;;;;)
    - * 
    - * - * Matches all methods named "arraycopy", with the first parameter of type "Object", and four more - * parameters of any type. The packages of the parameter types are irrelevant.
  • - *
  • - * - *
    - * com.oracle.graal.compiler.graph.PostOrderNodeIterator.*
    - * 
    - * - * Matches all methods in the class "com.oracle.graal.compiler.graph.PostOrderNodeIterator".
  • - *
  • - * - *
    - * *
    - * 
    - * - * Matches all methods in all classes
  • - *
  • - * - *
    - * com.oracle.graal.compiler.graph.*.visit
    - * 
    - * - * Matches all methods named "visit" in classes in the package "com.oracle.graal.compiler.graph". - *
  • - * - *
    - * arraycopy,toString
    - * 
    - * - * Matches all methods named "arraycopy" or "toString", meaning that ',' acts as an or - * operator.
  • - *
- */ -public class MethodFilter { - - private final Pattern clazz; - private final Pattern methodName; - private final Pattern[] signature; - - /** - * Parses a string containing list of comma separated filter patterns into an array of - * {@link MethodFilter}s. - */ - public static MethodFilter[] parse(String commaSeparatedPatterns) { - String[] filters = commaSeparatedPatterns.split(","); - MethodFilter[] methodFilters = new MethodFilter[filters.length]; - for (int i = 0; i < filters.length; i++) { - methodFilters[i] = new MethodFilter(filters[i]); - } - return methodFilters; - } - - /** - * Determines if a given method is matched by a given array of filters. - */ - public static boolean matches(MethodFilter[] filters, JavaMethod method) { - for (MethodFilter filter : filters) { - if (filter.matches(method)) { - return true; - } - } - return false; - } - - /** - * Determines if a given class name is matched by a given array of filters. - */ - public static boolean matchesClassName(MethodFilter[] filters, String className) { - for (MethodFilter filter : filters) { - if (filter.matchesClassName(className)) { - return true; - } - } - return false; - } - - public MethodFilter(String sourcePattern) { - String pattern = sourcePattern.trim(); - - // extract parameter part - int pos = pattern.indexOf('('); - if (pos != -1) { - if (pattern.charAt(pattern.length() - 1) != ')') { - throw new IllegalArgumentException("missing ')' at end of method filter pattern: " + pattern); - } - String[] signatureClasses = pattern.substring(pos + 1, pattern.length() - 1).split(";", -1); - signature = new Pattern[signatureClasses.length]; - for (int i = 0; i < signatureClasses.length; i++) { - signature[i] = createClassGlobPattern(signatureClasses[i].trim()); - } - pattern = pattern.substring(0, pos); - } else { - signature = null; - } - - // If there is at least one "." then everything before the last "." is the class name. - // Otherwise, the pattern contains only the method name. - pos = pattern.lastIndexOf('.'); - if (pos != -1) { - clazz = createClassGlobPattern(pattern.substring(0, pos)); - methodName = Pattern.compile(createGlobString(pattern.substring(pos + 1))); - } else { - clazz = null; - methodName = Pattern.compile(createGlobString(pattern)); - } - } - - public static String createGlobString(String pattern) { - return Pattern.quote(pattern).replace("?", "\\E.\\Q").replace("*", "\\E.*\\Q"); - } - - private static Pattern createClassGlobPattern(String pattern) { - if (pattern.length() == 0) { - return null; - } else if (pattern.contains(".")) { - return Pattern.compile(createGlobString(pattern)); - } else { - return Pattern.compile("([^\\.\\$]*[\\.\\$])*" + createGlobString(pattern)); - } - } - - /** - * Determines if the class part of this filter matches a given class name. - */ - public boolean matchesClassName(String className) { - return clazz == null || clazz.matcher(className).matches(); - } - - public boolean matches(JavaMethod o) { - // check method name first, since MetaUtil.toJavaName is expensive - if (methodName != null && !methodName.matcher(o.getName()).matches()) { - return false; - } - if (clazz != null && !clazz.matcher(o.getDeclaringClass().toJavaName()).matches()) { - return false; - } - if (signature != null) { - Signature sig = o.getSignature(); - if (sig.getParameterCount(false) != signature.length) { - return false; - } - for (int i = 0; i < signature.length; i++) { - JavaType type = sig.getParameterType(i, null); - String javaName = type.toJavaName(); - if (signature[i] != null && !signature[i].matcher(javaName).matches()) { - return false; - } - } - } - return true; - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder("MethodFilter["); - String sep = ""; - if (clazz != null) { - buf.append(sep).append("clazz=").append(clazz); - sep = ", "; - } - if (methodName != null) { - buf.append(sep).append("methodName=").append(methodName); - sep = ", "; - } - if (signature != null) { - buf.append(sep).append("signature=").append(Arrays.toString(signature)); - sep = ", "; - } - return buf.append("]").toString(); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/TopLevelDebugConfig.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/TopLevelDebugConfig.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug; - -/** - * A marker class for a scoped debug configuration covering a compilation region. Useful for - * programmatically enabling debug config features. - * - */ -public class TopLevelDebugConfig extends DelegatingDebugConfig { -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/AccumulatedDebugValue.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/AccumulatedDebugValue.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -public abstract class AccumulatedDebugValue extends DebugValue { - protected final DebugValue flat; - - public AccumulatedDebugValue(String name, boolean conditional, DebugValue flat) { - super(name + "_Accm", conditional); - this.flat = flat; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/CloseableCounterImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/CloseableCounterImpl.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import com.oracle.graal.debug.*; - -/** - * A helper class for DebugValues that can nest and need to split out accumulated and flat values - * for some kind of counter-like measurement. - */ -abstract class CloseableCounterImpl implements DebugCloseable { - - protected final CloseableCounterImpl parent; - protected final AccumulatedDebugValue counter; - protected final long start; - protected long nestedAmountToSubtract; - - CloseableCounterImpl(CloseableCounterImpl parent, AccumulatedDebugValue counter) { - this.parent = parent; - this.start = getCounterValue(); - this.counter = counter; - } - - @Override - public void close() { - long end = getCounterValue(); - long difference = end - start; - if (parent != null) { - if (!counter.getName().equals(parent.counter.getName())) { - parent.nestedAmountToSubtract += difference; - - // Look for our counter in an outer scope and fix up - // the adjustment to the flat count - CloseableCounterImpl ancestor = parent.parent; - while (ancestor != null) { - if (ancestor.counter.getName().equals(counter.getName())) { - ancestor.nestedAmountToSubtract -= difference; - break; - } - ancestor = ancestor.parent; - } - } - } - long flatAmount = difference - nestedAmountToSubtract; - counter.addToCurrentValue(difference); - counter.flat.addToCurrentValue(flatAmount); - } - - abstract long getCounterValue(); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramAsciiPrinter.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramAsciiPrinter.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import java.io.*; -import java.util.*; - -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.DebugHistogram.*; - -/** - * Renders a textual representation of a histogram to a given print stream. - */ -public class DebugHistogramAsciiPrinter implements Printer { - - public static final int NumberSize = 10; - public static final int DefaultNameSize = 50; - public static final int DefaultBarSize = 100; - public static final int DefaultScale = 1; - - private final PrintStream os; - private final int limit; - private final int nameSize; - private final int barSize; - private final int scale; - - public DebugHistogramAsciiPrinter(PrintStream os) { - this(os, Integer.MAX_VALUE, DefaultNameSize, DefaultBarSize, DefaultScale); - } - - /** - * @param os where to print - * @param limit limits printing to the {@code limit} most frequent values - * @param nameSize the width of the value names column - * @param barSize the width of the value frequency column - * @param scale a factor by which every result is divided - */ - public DebugHistogramAsciiPrinter(PrintStream os, int limit, int nameSize, int barSize, int scale) { - this.os = os; - this.limit = limit; - this.nameSize = nameSize; - this.barSize = barSize; - this.scale = scale; - } - - public void print(DebugHistogram histogram) { - List list = histogram.getValues(); - if (list.isEmpty()) { - os.printf("%s is empty.%n", histogram.getName()); - return; - } - - // Sum up the total number of elements. - long total = list.stream().mapToLong(CountedValue::getCount).sum(); - - // Print header. - os.printf("%s has %d unique elements and %d total elements:%n", histogram.getName(), list.size(), total / scale); - - long max = list.get(0).getCount() / scale; - final int lineSize = nameSize + NumberSize + barSize + 10; - printLine(os, '-', lineSize); - String formatString = "| %-" + nameSize + "s | %-" + NumberSize + "d | %-" + barSize + "s |\n"; - for (int i = 0; i < list.size() && i < limit; ++i) { - CountedValue cv = list.get(i); - long value = cv.getCount() / scale; - char[] bar = new char[(int) (((double) value / (double) max) * barSize)]; - Arrays.fill(bar, '='); - String objectString = String.valueOf(cv.getValue()); - if (objectString.length() > nameSize) { - objectString = objectString.substring(0, nameSize - 3) + "..."; - } - os.printf(formatString, objectString, value, new String(bar)); - } - printLine(os, '-', lineSize); - } - - private static void printLine(PrintStream printStream, char c, int lineSize) { - char[] charArr = new char[lineSize]; - Arrays.fill(charArr, c); - printStream.printf("%s%n", new String(charArr)); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import java.util.*; - -import com.oracle.graal.debug.*; - -public class DebugHistogramImpl implements DebugHistogram { - - private final String name; - private HashMap map = new HashMap<>(); - - public DebugHistogramImpl(String name) { - this.name = name; - } - - public void add(Object value) { - CountedValue cv = map.get(value); - if (cv == null) { - map.put(value, new CountedValue(1, value)); - } else { - cv.inc(); - } - } - - public void add(Object value, long count) { - CountedValue cv = map.get(value); - if (cv == null) { - map.put(value, new CountedValue(count, value)); - } else { - cv.add(count); - } - } - - @Override - public String getName() { - return name; - } - - public List getValues() { - ArrayList res = new ArrayList<>(map.values()); - Collections.sort(res); - return res; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramRPrinter.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramRPrinter.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import java.io.*; -import java.util.*; - -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.DebugHistogram.*; - -/** - * Renders a histogram as an R script to a given print stream. The R script emitted for a histogram - * is a simple set of statements for defining a vector of named objects. - */ -public class DebugHistogramRPrinter implements Printer { - - private PrintStream os; - private int limit; - - public DebugHistogramRPrinter(PrintStream os) { - this(os, Integer.MAX_VALUE); - } - - /** - * @param os where to print - * @param limit limits printing to the {@code limit} most frequent values - */ - public DebugHistogramRPrinter(PrintStream os, int limit) { - this.os = os; - this.limit = limit; - } - - public void print(DebugHistogram histogram) { - List list = histogram.getValues(); - if (list.isEmpty()) { - return; - } - - String var = histogram.getName().replace('-', '.').replace(' ', '_'); - os.print(var + " <- c("); - for (int i = 0; i < list.size() && i < limit; ++i) { - CountedValue cv = list.get(i); - if (i != 0) { - os.print(", "); - } - os.print(cv.getCount()); - } - os.println(");"); - - os.print("names(" + var + ") <- c("); - for (int i = 0; i < list.size() && i < limit; ++i) { - CountedValue cv = list.get(i); - if (i != 0) { - os.print(", "); - } - os.print("\"" + cv.getValue() + "\""); - } - os.println(");"); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,489 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import java.io.*; -import java.util.*; -import java.util.concurrent.*; - -import jdk.internal.jvmci.debug.*; - -import com.oracle.graal.debug.*; - -public final class DebugScope implements Debug.Scope { - - private final class IndentImpl implements Indent { - - private static final String INDENTATION_INCREMENT = " "; - - final String indent; - final IndentImpl parentIndent; - - IndentImpl(IndentImpl parentIndent) { - this.parentIndent = parentIndent; - this.indent = (parentIndent == null ? "" : parentIndent.indent + INDENTATION_INCREMENT); - } - - private void printScopeName(StringBuilder str) { - if (logScopeName) { - if (parentIndent != null) { - parentIndent.printScopeName(str); - } - str.append(indent).append("[thread:").append(Thread.currentThread().getId()).append("] scope: ").append(getQualifiedName()).append(System.lineSeparator()); - logScopeName = false; - } - } - - public void log(int logLevel, String msg, Object... args) { - if (isLogEnabled(logLevel)) { - StringBuilder str = new StringBuilder(); - printScopeName(str); - str.append(indent); - String result = args.length == 0 ? msg : String.format(msg, args); - String lineSep = System.lineSeparator(); - str.append(result.replace(lineSep, lineSep.concat(indent))); - str.append(lineSep); - output.append(str); - lastUsedIndent = this; - } - } - - IndentImpl indent() { - lastUsedIndent = new IndentImpl(this); - return lastUsedIndent; - } - - @Override - public void close() { - if (parentIndent != null) { - lastUsedIndent = parentIndent; - } - } - } - - private static final ThreadLocal instanceTL = new ThreadLocal<>(); - private static final ThreadLocal lastClosedTL = new ThreadLocal<>(); - private static final ThreadLocal configTL = new ThreadLocal<>(); - private static final ThreadLocal lastExceptionThrownTL = new ThreadLocal<>(); - - private final DebugScope parent; - private final DebugConfig parentConfig; - private final boolean sandbox; - private IndentImpl lastUsedIndent; - private boolean logScopeName; - - private final Object[] context; - - private DebugValueMap valueMap; - - private String qualifiedName; - private final String unqualifiedName; - - private static final char SCOPE_SEP = '.'; - - private boolean meterEnabled; - private boolean timeEnabled; - private boolean memUseTrackingEnabled; - private boolean verifyEnabled; - - private int currentDumpLevel; - private int currentLogLevel; - - private PrintStream output; - - public static DebugScope getInstance() { - DebugScope result = instanceTL.get(); - if (result == null) { - DebugScope topLevelDebugScope = new DebugScope(Thread.currentThread()); - instanceTL.set(topLevelDebugScope); - return topLevelDebugScope; - } else { - return result; - } - } - - public static DebugConfig getConfig() { - return configTL.get(); - } - - static final Object[] EMPTY_CONTEXT = new Object[0]; - - private DebugScope(Thread thread) { - this(thread.getName(), null, false); - computeValueMap(thread.getName()); - DebugValueMap.registerTopLevel(getValueMap()); - } - - private DebugScope(String unqualifiedName, DebugScope parent, boolean sandbox, Object... context) { - this.parent = parent; - this.sandbox = sandbox; - this.parentConfig = getConfig(); - this.context = context; - this.unqualifiedName = unqualifiedName; - if (parent != null) { - logScopeName = !unqualifiedName.equals(""); - } else { - logScopeName = true; - } - - this.output = TTY.out; - assert context != null; - } - - private void computeValueMap(String name) { - if (parent != null) { - for (DebugValueMap child : parent.getValueMap().getChildren()) { - if (child.getName().equals(name)) { - this.valueMap = child; - return; - } - } - this.valueMap = new DebugValueMap(name); - parent.getValueMap().addChild(this.valueMap); - } else { - this.valueMap = new DebugValueMap(name); - } - } - - public void close() { - instanceTL.set(parent); - configTL.set(parentConfig); - lastClosedTL.set(this); - } - - public boolean isDumpEnabled(int dumpLevel) { - assert dumpLevel > 0; - return currentDumpLevel >= dumpLevel; - } - - /** - * Enable dumping at the new {@code dumpLevel} for the remainder of enclosing scopes. This only - * works if a {@link TopLevelDebugConfig} was installed at a higher scope. - * - * @param dumpLevel - */ - public static void setDumpLevel(int dumpLevel) { - TopLevelDebugConfig config = fetchTopLevelDebugConfig("setDebugLevel"); - if (config != null) { - config.override(DelegatingDebugConfig.Level.DUMP, dumpLevel); - recursiveUpdateFlags(); - } - } - - /** - * Enable logging at the new {@code logLevel} for the remainder of enclosing scopes. This only - * works if a {@link TopLevelDebugConfig} was installed at a higher scope. - * - * @param logLevel - */ - public static void setLogLevel(int logLevel) { - TopLevelDebugConfig config = fetchTopLevelDebugConfig("setLogLevel"); - if (config != null) { - config.override(DelegatingDebugConfig.Level.LOG, logLevel); - config.delegate(DelegatingDebugConfig.Feature.LOG_METHOD); - recursiveUpdateFlags(); - } - } - - private static void recursiveUpdateFlags() { - DebugScope c = DebugScope.getInstance(); - while (c != null) { - c.updateFlags(); - c = c.parent; - } - } - - private static TopLevelDebugConfig fetchTopLevelDebugConfig(String msg) { - DebugConfig config = getConfig(); - if (config instanceof TopLevelDebugConfig) { - return (TopLevelDebugConfig) config; - } else { - if (config == null) { - TTY.println("DebugScope.%s ignored because debugging is disabled", msg); - } else { - TTY.println("DebugScope.%s ignored because top level delegate config missing", msg); - } - return null; - } - } - - public boolean isVerifyEnabled() { - return verifyEnabled; - } - - public boolean isLogEnabled(int logLevel) { - assert logLevel > 0; - return currentLogLevel >= logLevel; - } - - public boolean isMeterEnabled() { - return meterEnabled; - } - - public boolean isTimeEnabled() { - return timeEnabled; - } - - public boolean isMemUseTrackingEnabled() { - return memUseTrackingEnabled; - } - - public void log(int logLevel, String msg, Object... args) { - if (isLogEnabled(logLevel)) { - getLastUsedIndent().log(logLevel, msg, args); - } - } - - public void dump(int dumpLevel, Object object, String formatString, Object... args) { - if (isDumpEnabled(dumpLevel)) { - DebugConfig config = getConfig(); - if (config != null) { - String message = String.format(formatString, args); - for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { - dumpHandler.dump(object, message); - } - } - } - } - - /** - * This method exists mainly to allow a debugger (e.g., Eclipse) to force dump a graph. - */ - public static void forceDump(Object object, String format, Object... args) { - DebugConfig config = getConfig(); - if (config != null) { - String message = String.format(format, args); - for (DebugDumpHandler dumpHandler : config.dumpHandlers()) { - dumpHandler.dump(object, message); - } - } else { - TTY.println("Forced dump ignored because debugging is disabled - use -G:Dump=xxx option"); - } - } - - /** - * @see Debug#verify(Object, String) - */ - public void verify(Object object, String formatString, Object... args) { - if (isVerifyEnabled()) { - DebugConfig config = getConfig(); - if (config != null) { - String message = String.format(formatString, args); - for (DebugVerifyHandler handler : config.verifyHandlers()) { - handler.verify(object, message); - } - } - } - } - - /** - * Creates and enters a new debug scope which is either a child of the current scope or a - * disjoint top level scope. - * - * @param name the name of the new scope - * @param sandboxConfig the configuration to use for a new top level scope, or null if the new - * scope should be a child scope - * @param newContextObjects objects to be appended to the debug context - * @return the new scope which will be exited when its {@link #close()} method is called - */ - public DebugScope scope(CharSequence name, DebugConfig sandboxConfig, Object... newContextObjects) { - DebugScope newScope = null; - if (sandboxConfig != null) { - newScope = new DebugScope(name.toString(), this, true, newContextObjects); - configTL.set(sandboxConfig); - } else { - newScope = this.createChild(name.toString(), newContextObjects); - } - instanceTL.set(newScope); - newScope.updateFlags(); - return newScope; - } - - public RuntimeException handle(Throwable e) { - DebugScope lastClosed = lastClosedTL.get(); - assert lastClosed.parent == this : "Debug.handle() used with no matching Debug.scope(...) or Debug.sandbox(...)"; - if (e != lastExceptionThrownTL.get()) { - RuntimeException newException = null; - instanceTL.set(lastClosed); - try (DebugScope s = lastClosed) { - newException = s.interceptException(e); - } - assert instanceTL.get() == this; - assert lastClosed == lastClosedTL.get(); - if (newException == null) { - lastExceptionThrownTL.set(e); - } else { - lastExceptionThrownTL.set(newException); - throw newException; - } - } - if (e instanceof Error) { - throw (Error) e; - } - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } - throw new RuntimeException(e); - } - - private void updateFlags() { - DebugConfig config = getConfig(); - if (config == null) { - meterEnabled = false; - memUseTrackingEnabled = false; - timeEnabled = false; - verifyEnabled = false; - - currentDumpLevel = 0; - - // Be pragmatic: provide a default log stream to prevent a crash if the stream is not - // set while logging - output = TTY.out; - } else { - meterEnabled = config.isMeterEnabled(); - memUseTrackingEnabled = config.isMemUseTrackingEnabled(); - timeEnabled = config.isTimeEnabled(); - verifyEnabled = config.isVerifyEnabled(); - output = config.output(); - currentDumpLevel = config.getDumpLevel(); - currentLogLevel = config.getLogLevel(); - } - } - - private RuntimeException interceptException(final Throwable e) { - final DebugConfig config = getConfig(); - if (config != null) { - try (DebugScope s = scope("InterceptException", null, e)) { - return config.interceptException(e); - } catch (Throwable t) { - return new RuntimeException("Exception while intercepting exception", t); - } - } - return null; - } - - private DebugValueMap getValueMap() { - if (valueMap == null) { - computeValueMap(unqualifiedName); - } - return valueMap; - } - - long getCurrentValue(int index) { - return getValueMap().getCurrentValue(index); - } - - void setCurrentValue(int index, long l) { - getValueMap().setCurrentValue(index, l); - } - - private DebugScope createChild(String newName, Object[] newContext) { - return new DebugScope(newName, this, false, newContext); - } - - public Iterable getCurrentContext() { - final DebugScope scope = this; - return new Iterable() { - - @Override - public Iterator iterator() { - return new Iterator() { - - DebugScope currentScope = scope; - int objectIndex; - - @Override - public boolean hasNext() { - selectScope(); - return currentScope != null; - } - - private void selectScope() { - while (currentScope != null && currentScope.context.length <= objectIndex) { - currentScope = currentScope.sandbox ? null : currentScope.parent; - objectIndex = 0; - } - } - - @Override - public Object next() { - selectScope(); - if (currentScope != null) { - return currentScope.context[objectIndex++]; - } - throw new IllegalStateException("May only be called if there is a next element."); - } - - @Override - public void remove() { - throw new UnsupportedOperationException("This iterator is read only."); - } - }; - } - }; - } - - public static T call(Callable callable) { - try { - return callable.call(); - } catch (Exception e) { - if (e instanceof RuntimeException) { - throw (RuntimeException) e; - } else { - throw new RuntimeException(e); - } - } - } - - public void setConfig(DebugConfig newConfig) { - configTL.set(newConfig); - updateFlags(); - } - - public String getQualifiedName() { - if (qualifiedName == null) { - if (parent == null) { - qualifiedName = unqualifiedName; - } else { - qualifiedName = parent.getQualifiedName() + SCOPE_SEP + unqualifiedName; - } - } - return qualifiedName; - } - - public Indent pushIndentLogger() { - lastUsedIndent = getLastUsedIndent().indent(); - return lastUsedIndent; - } - - public IndentImpl getLastUsedIndent() { - if (lastUsedIndent == null) { - if (parent != null) { - lastUsedIndent = new IndentImpl(parent.getLastUsedIndent()); - } else { - lastUsedIndent = new IndentImpl(null); - } - } - return lastUsedIndent; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValue.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValue.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -/** - * A name and index for a value managed in a thread local value map. All access to the value is made - * via a {@link DebugValue} instance. - */ -public abstract class DebugValue implements Comparable { - - private final String name; - private int index; - private boolean conditional; - - protected DebugValue(String name, boolean conditional) { - this.name = name; - this.index = -1; - this.conditional = conditional; - } - - public long getCurrentValue() { - ensureInitialized(); - return DebugScope.getInstance().getCurrentValue(index); - } - - protected void setCurrentValue(long l) { - ensureInitialized(); - DebugScope.getInstance().setCurrentValue(index, l); - } - - public void setConditional(boolean flag) { - conditional = flag; - } - - public boolean isConditional() { - return conditional; - } - - private void ensureInitialized() { - if (index == -1) { - index = KeyRegistry.register(this); - } - } - - protected void addToCurrentValue(long value) { - setCurrentValue(getCurrentValue() + value); - } - - /** - * Gets the globally unique index for the value represented by this object. - */ - public int getIndex() { - ensureInitialized(); - return index; - } - - /** - * Gets the globally unique name for the value represented by this object. - */ - public String getName() { - return name; - } - - public int compareTo(DebugValue o) { - return name.compareTo(o.name); - } - - @Override - public String toString() { - return name + "@" + index; - } - - public abstract String toString(long value); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import java.util.*; - -/** - * A node in a tree of {@link DebugValue}s. - */ -public class DebugValueMap { - - private static final List topLevelMaps = new ArrayList<>(); - - private long[] values; - private List children; - private String name; - - public DebugValueMap(String name) { - this.name = name; - } - - public void setCurrentValue(int index, long l) { - ensureSize(index); - values[index] = l; - } - - public long getCurrentValue(int index) { - ensureSize(index); - return values[index]; - } - - public void clearChildren() { - if (children != null) { - children.clear(); - } - } - - public void reset() { - if (values != null) { - Arrays.fill(values, 0L); - } - if (children != null) { - for (DebugValueMap child : children) { - child.reset(); - } - } - } - - private void ensureSize(int index) { - if (values == null) { - values = new long[index + 1]; - } - if (values.length <= index) { - values = Arrays.copyOf(values, index + 1); - } - } - - private int capacity() { - return (values == null) ? 0 : values.length; - } - - public void addChild(DebugValueMap map) { - if (children == null) { - children = new ArrayList<>(4); - } - children.add(map); - } - - public List getChildren() { - if (children == null) { - return Collections.emptyList(); - } else { - return Collections.unmodifiableList(children); - } - } - - public boolean hasChildren() { - return children != null && !children.isEmpty(); - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return "DebugValueMap<" + getName() + ">"; - } - - public static synchronized void registerTopLevel(DebugValueMap map) { - topLevelMaps.add(map); - } - - public static synchronized List getTopLevelMaps() { - return topLevelMaps; - } - - public void normalize() { - if (hasChildren()) { - Map occurred = new HashMap<>(); - for (DebugValueMap map : children) { - String mapName = map.getName(); - if (!occurred.containsKey(mapName)) { - occurred.put(mapName, map); - map.normalize(); - } else { - occurred.get(mapName).mergeWith(map); - occurred.get(mapName).normalize(); - } - } - - if (occurred.values().size() < children.size()) { - // At least one duplicate was found. - children.clear(); - for (DebugValueMap map : occurred.values()) { - addChild(map); - map.normalize(); - } - } - } - } - - private void mergeWith(DebugValueMap map) { - if (map.hasChildren()) { - if (hasChildren()) { - children.addAll(map.children); - } else { - children = map.children; - } - map.children = null; - } - - int size = Math.max(this.capacity(), map.capacity()); - ensureSize(size); - for (int i = 0; i < size; ++i) { - long curValue = getCurrentValue(i); - long otherValue = map.getCurrentValue(i); - setCurrentValue(i, curValue + otherValue); - } - } - - public void group() { - if (this.hasChildren()) { - List oldChildren = new ArrayList<>(this.children); - this.children.clear(); - for (DebugValueMap map : oldChildren) { - mergeWith(map); - } - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/KeyRegistry.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/KeyRegistry.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import java.util.*; - -/** - * Registry for allocating a globally unique integer id to each {@link DebugValue}. - */ -public class KeyRegistry { - - private static final Map keyMap = new HashMap<>(); - private static final List debugValues = new ArrayList<>(); - - /** - * Ensures a given debug value is registered. - * - * @return the globally unique id for {@code value} - */ - public static synchronized int register(DebugValue value) { - String name = value.getName(); - if (!keyMap.containsKey(name)) { - keyMap.put(name, debugValues.size()); - debugValues.add(value); - } - return keyMap.get(name); - } - - /** - * Gets a immutable view of the registered debug values. - * - * @return a list where {@code get(i).getIndex() == i} - */ - public static synchronized List getDebugValues() { - return Collections.unmodifiableList(debugValues); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MemUseTrackerImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MemUseTrackerImpl.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import static com.oracle.graal.debug.DebugCloseable.*; -import jdk.internal.jvmci.debug.*; - -import com.oracle.graal.debug.*; - -public final class MemUseTrackerImpl extends AccumulatedDebugValue implements DebugMemUseTracker { - - public static long getCurrentThreadAllocatedBytes() { - return Management.getCurrentThreadAllocatedBytes(); - } - - /** - * Records the most recent active tracker. - */ - private static final ThreadLocal currentTracker = new ThreadLocal<>(); - - public MemUseTrackerImpl(String name, boolean conditional) { - super(name, conditional, new DebugValue(name + "_Flat", conditional) { - - @Override - public String toString(long value) { - return valueToString(value); - } - }); - } - - @Override - public DebugCloseable start() { - if (!isConditional() || Debug.isMemUseTrackingEnabled()) { - MemUseCloseableCounterImpl result = new MemUseCloseableCounterImpl(this); - currentTracker.set(result); - return result; - } else { - return VOID_CLOSEABLE; - } - } - - public static String valueToString(long value) { - return String.format("%d bytes", value); - } - - @Override - public String toString(long value) { - return valueToString(value); - } - - private static final class MemUseCloseableCounterImpl extends CloseableCounterImpl implements DebugCloseable { - - private MemUseCloseableCounterImpl(AccumulatedDebugValue counter) { - super(currentTracker.get(), counter); - } - - @Override - long getCounterValue() { - return getCurrentThreadAllocatedBytes(); - } - - @Override - public void close() { - super.close(); - currentTracker.set(parent); - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MetricImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/MetricImpl.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import com.oracle.graal.debug.*; - -public final class MetricImpl extends DebugValue implements DebugMetric { - - public MetricImpl(String name, boolean conditional) { - super(name, conditional); - if (isEnabled()) { - // Allows for zero-count metrics to be shown - getCurrentValue(); - } - } - - public void increment() { - add(1); - } - - public void add(long value) { - if (isEnabled()) { - super.addToCurrentValue(value); - } - } - - @Override - public String toString(long value) { - return Long.toString(value); - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.debug.internal; - -import static com.oracle.graal.debug.DebugCloseable.*; - -import java.lang.management.*; -import java.util.concurrent.*; - -import jdk.internal.jvmci.debug.*; - -import com.oracle.graal.debug.*; - -public final class TimerImpl extends AccumulatedDebugValue implements DebugTimer { - - private static final ThreadMXBean threadMXBean = Management.getThreadMXBean(); - - /** - * Records the most recent active timer. - */ - private static final ThreadLocal currentTimer = new ThreadLocal<>(); - - static class FlatTimer extends DebugValue implements DebugTimer { - private TimerImpl accm; - - public FlatTimer(String name, boolean conditional) { - super(name + "_Flat", conditional); - } - - @Override - public String toString(long value) { - return valueToString(value); - } - - public TimeUnit getTimeUnit() { - return accm.getTimeUnit(); - } - - public DebugCloseable start() { - return accm.start(); - } - } - - public TimerImpl(String name, boolean conditional) { - super(name, conditional, new FlatTimer(name, conditional)); - ((FlatTimer) flat).accm = this; - } - - @Override - public DebugCloseable start() { - if (!isConditional() || Debug.isTimeEnabled()) { - AbstractTimer result; - if (threadMXBean.isCurrentThreadCpuTimeSupported()) { - result = new CpuTimeTimer(this); - } else { - result = new SystemNanosTimer(this); - } - currentTimer.set(result); - return result; - } else { - return VOID_CLOSEABLE; - } - } - - public static String valueToString(long value) { - return String.format("%d.%d ms", value / 1000000, (value / 100000) % 10); - } - - public DebugTimer getFlat() { - return (FlatTimer) flat; - } - - @Override - public String toString(long value) { - return valueToString(value); - } - - public TimeUnit getTimeUnit() { - return TimeUnit.NANOSECONDS; - } - - private abstract static class AbstractTimer extends CloseableCounterImpl implements DebugCloseable { - - private AbstractTimer(AccumulatedDebugValue counter) { - super(currentTimer.get(), counter); - } - - @Override - public void close() { - super.close(); - currentTimer.set(parent); - } - } - - private final class SystemNanosTimer extends AbstractTimer { - - public SystemNanosTimer(TimerImpl timer) { - super(timer); - } - - @Override - protected long getCounterValue() { - return System.nanoTime(); - } - } - - private final class CpuTimeTimer extends AbstractTimer { - - public CpuTimeTimer(TimerImpl timer) { - super(timer); - } - - @Override - protected long getCounterValue() { - return threadMXBean.getCurrentThreadCpuTime(); - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEpilogueBlockEndOp.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotEpilogueBlockEndOp.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot.amd64; - -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.amd64.*; -import com.oracle.graal.lir.asm.*; - -import jdk.internal.jvmci.meta.*; - -/** - * @see AMD64HotSpotEpilogueOp - */ -abstract class AMD64HotSpotEpilogueBlockEndOp extends AMD64BlockEndOp { - - protected AMD64HotSpotEpilogueBlockEndOp(LIRInstructionClass c, AllocatableValue savedRbp) { - super(c); - this.savedRbp = savedRbp; - } - - @Use({REG, STACK}) private AllocatableValue savedRbp; - - protected void leaveFrameAndRestoreRbp(CompilationResultBuilder crb, AMD64MacroAssembler masm) { - AMD64HotSpotEpilogueOp.leaveFrameAndRestoreRbp(savedRbp, crb, masm); - } - -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationStatistics.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationStatistics.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot; - -import static java.lang.Thread.*; - -import java.io.*; -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; - -import jdk.internal.jvmci.debug.*; -import jdk.internal.jvmci.hotspot.*; - -import com.sun.management.*; - -@SuppressWarnings("unused") -public final class CompilationStatistics { - - private static final long RESOLUTION = 100000000; - private static final boolean ENABLED = Boolean.getBoolean("jvmci.comp.stats"); - - private static final CompilationStatistics DUMMY = new CompilationStatistics(null, false); - - private static ConcurrentLinkedDeque list = new ConcurrentLinkedDeque<>(); - - private static final ThreadLocal> current = new ThreadLocal>() { - - @Override - protected Deque initialValue() { - return new ArrayDeque<>(); - } - }; - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - private static @interface NotReported { - } - - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - private static @interface TimeValue { - } - - private static long zeroTime = System.nanoTime(); - - private static long getThreadAllocatedBytes() { - ThreadMXBean thread = (ThreadMXBean) Management.getThreadMXBean(); - return thread.getThreadAllocatedBytes(currentThread().getId()); - } - - @NotReported private final long startTime; - @NotReported private long threadAllocatedBytesStart; - - private int bytecodeCount; - private int codeSize; - @TimeValue private long duration; - private long memoryUsed; - private final boolean osr; - private final String holder; - private final String name; - private final String signature; - - private CompilationStatistics(HotSpotResolvedJavaMethod method, boolean osr) { - this.osr = osr; - if (method != null) { - holder = method.getDeclaringClass().getName(); - name = method.getName(); - signature = method.getSignature().toMethodDescriptor(); - startTime = System.nanoTime(); - bytecodeCount = method.getCodeSize(); - threadAllocatedBytesStart = getThreadAllocatedBytes(); - } else { - holder = ""; - name = ""; - signature = ""; - startTime = 0; - } - } - - public void finish(HotSpotResolvedJavaMethod method, HotSpotInstalledCode code) { - if (ENABLED) { - duration = System.nanoTime() - startTime; - codeSize = (int) code.getCodeSize(); - memoryUsed = getThreadAllocatedBytes() - threadAllocatedBytesStart; - if (current.get().getLast() != this) { - throw new RuntimeException("mismatch in finish()"); - } - current.get().removeLast(); - } - } - - public static CompilationStatistics current() { - return current.get().isEmpty() ? null : current.get().getLast(); - } - - public static CompilationStatistics create(HotSpotResolvedJavaMethod method, boolean isOSR) { - if (ENABLED) { - CompilationStatistics stats = new CompilationStatistics(method, isOSR); - list.add(stats); - current.get().addLast(stats); - return stats; - } else { - return DUMMY; - } - } - - @SuppressWarnings("deprecation") - public static void clear(String dumpName) { - if (!ENABLED) { - return; - } - try { - ConcurrentLinkedDeque snapshot = list; - long snapshotZeroTime = zeroTime; - - list = new ConcurrentLinkedDeque<>(); - zeroTime = System.nanoTime(); - - Date now = new Date(); - String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes(); - - dumpCompilations(snapshot, dumpName, dateString); - - try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) { - - long[] timeSpent = new long[10000]; - int maxTick = 0; - for (CompilationStatistics stats : snapshot) { - long start = stats.startTime - snapshotZeroTime; - long duration = stats.duration; - if (start < 0) { - duration -= -start; - start = 0; - } - - int tick = (int) (start / RESOLUTION); - long timeLeft = RESOLUTION - (start % RESOLUTION); - - while (tick < timeSpent.length && duration > 0) { - if (tick > maxTick) { - maxTick = tick; - } - timeSpent[tick] += Math.min(timeLeft, duration); - duration -= timeLeft; - tick++; - timeLeft = RESOLUTION; - } - } - String timelineName = System.getProperty("stats.timeline.name"); - if (timelineName != null && !timelineName.isEmpty()) { - out.print(timelineName + "\t"); - } - for (int i = 0; i <= maxTick; i++) { - out.print((timeSpent[i] * 100 / RESOLUTION) + "\t"); - } - out.println(); - } - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - protected static void dumpCompilations(ConcurrentLinkedDeque snapshot, String dumpName, String dateString) throws IllegalAccessException, FileNotFoundException { - String fileName = "compilations_" + dateString + "_" + dumpName + ".csv"; - try (PrintStream out = new PrintStream(fileName)) { - // output the list of all compilations - - Field[] declaredFields = CompilationStatistics.class.getDeclaredFields(); - ArrayList fields = new ArrayList<>(); - for (Field field : declaredFields) { - if (!Modifier.isStatic(field.getModifiers()) && !field.isAnnotationPresent(NotReported.class)) { - fields.add(field); - } - } - for (Field field : fields) { - out.print(field.getName() + "\t"); - } - out.println(); - for (CompilationStatistics stats : snapshot) { - for (Field field : fields) { - if (field.isAnnotationPresent(TimeValue.class)) { - double value = field.getLong(stats) / 1000000d; - out.print(String.format(Locale.ENGLISH, "%.3f", value) + "\t"); - } else { - out.print(field.get(stats) + "\t"); - } - } - out.println(); - } - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot; - -import static jdk.internal.jvmci.common.UnsafeAccess.*; -import static jdk.internal.jvmci.compiler.Compiler.*; - -import java.util.concurrent.*; - -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.debug.internal.*; - -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.compiler.Compiler; -import jdk.internal.jvmci.debug.*; -import jdk.internal.jvmci.hotspot.*; -import jdk.internal.jvmci.hotspot.events.*; -import jdk.internal.jvmci.hotspot.events.EventProvider.CompilationEvent; -import jdk.internal.jvmci.hotspot.events.EventProvider.CompilerFailureEvent; -import jdk.internal.jvmci.meta.*; -import jdk.internal.jvmci.service.*; - -//JaCoCo Exclude - -public class CompilationTask { - - private static final DebugMetric BAILOUTS = Debug.metric("Bailouts"); - - private static final EventProvider eventProvider; - static { - EventProvider provider = Services.loadSingle(EventProvider.class, false); - if (provider == null) { - eventProvider = new EmptyEventProvider(); - } else { - eventProvider = provider; - } - } - private static final Compiler compiler = Services.loadSingle(Compiler.class, true); - - private final HotSpotResolvedJavaMethod method; - private final int entryBCI; - private final int id; - - /** - * Specifies whether the compilation result is installed as the - * {@linkplain HotSpotNmethod#isDefault() default} nmethod for the compiled method. - */ - private final boolean installAsDefault; - - static class Lazy { - /** - * A {@link com.sun.management.ThreadMXBean} to be able to query some information about the - * current compiler thread, e.g. total allocated bytes. - */ - static final com.sun.management.ThreadMXBean threadMXBean = (com.sun.management.ThreadMXBean) Management.getThreadMXBean(); - } - - /** - * The address of the JVMCIEnv associated with this compilation or 0L if no such object exists. - */ - private final long jvmciEnv; - - public CompilationTask(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id, boolean installAsDefault) { - this.method = method; - this.entryBCI = entryBCI; - this.id = id; - this.jvmciEnv = jvmciEnv; - this.installAsDefault = installAsDefault; - } - - public ResolvedJavaMethod getMethod() { - return method; - } - - /** - * Returns the compilation id of this task. - * - * @return compile id - */ - public int getId() { - return id; - } - - public int getEntryBCI() { - return entryBCI; - } - - /** - * Time spent in compilation. - */ - private static final DebugTimer CompilationTime = Debug.timer("CompilationTime"); - - /** - * Meters the {@linkplain CompilationResult#getBytecodeSize() bytecodes} compiled. - */ - private static final DebugMetric CompiledBytecodes = Debug.metric("CompiledBytecodes"); - - public static final DebugTimer CodeInstallationTime = Debug.timer("CodeInstallation"); - - public void runCompilation() { - HotSpotVMConfig config = HotSpotJVMCIRuntime.runtime().getConfig(); - final long threadId = Thread.currentThread().getId(); - long startCompilationTime = System.nanoTime(); - HotSpotInstalledCode installedCode = null; - final boolean isOSR = entryBCI != Compiler.INVOCATION_ENTRY_BCI; - - // Log a compilation event. - CompilationEvent compilationEvent = eventProvider.newCompilationEvent(); - - // If there is already compiled code for this method on our level we simply return. - // JVMCI compiles are always at the highest compile level, even in non-tiered mode so we - // only need to check for that value. - if (method.hasCodeAtLevel(entryBCI, config.compilationLevelFullOptimization)) { - return; - } - - CompilationResult result = null; - try (DebugCloseable a = CompilationTime.start()) { - CompilationStatistics stats = CompilationStatistics.create(method, isOSR); - final boolean printCompilation = PrintCompilation.getValue() && !TTY.isSuppressed(); - final boolean printAfterCompilation = PrintAfterCompilation.getValue() && !TTY.isSuppressed(); - if (printCompilation) { - TTY.println(getMethodDescription() + "..."); - } - - TTY.Filter filter = new TTY.Filter(PrintFilter.getValue(), method); - final long start; - final long allocatedBytesBefore; - if (printAfterCompilation || printCompilation) { - start = System.currentTimeMillis(); - allocatedBytesBefore = printAfterCompilation || printCompilation ? Lazy.threadMXBean.getThreadAllocatedBytes(threadId) : 0L; - } else { - start = 0L; - allocatedBytesBefore = 0L; - } - - try (Scope s = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true))) { - // Begin the compilation event. - compilationEvent.begin(); - - result = compiler.compile(method, entryBCI, mustRecordMethodInlining(config)); - - result.setId(getId()); - } catch (Throwable e) { - throw Debug.handle(e); - } finally { - // End the compilation event. - compilationEvent.end(); - - filter.remove(); - - if (printAfterCompilation || printCompilation) { - final long stop = System.currentTimeMillis(); - final int targetCodeSize = result != null ? result.getTargetCodeSize() : -1; - final long allocatedBytesAfter = Lazy.threadMXBean.getThreadAllocatedBytes(threadId); - final long allocatedBytes = (allocatedBytesAfter - allocatedBytesBefore) / 1024; - - if (printAfterCompilation) { - TTY.println(getMethodDescription() + String.format(" | %4dms %5dB %5dkB", stop - start, targetCodeSize, allocatedBytes)); - } else if (printCompilation) { - TTY.println(String.format("%-6d JVMCI %-70s %-45s %-50s | %4dms %5dB %5dkB", id, "", "", "", stop - start, targetCodeSize, allocatedBytes)); - } - } - } - - try (DebugCloseable b = CodeInstallationTime.start()) { - installedCode = (HotSpotInstalledCode) installMethod(result); - } - stats.finish(method, installedCode); - } catch (BailoutException bailout) { - BAILOUTS.increment(); - if (ExitVMOnBailout.getValue()) { - TTY.out.println(method.format("Bailout in %H.%n(%p)")); - bailout.printStackTrace(TTY.out); - System.exit(-1); - } else if (PrintBailout.getValue()) { - TTY.out.println(method.format("Bailout in %H.%n(%p)")); - bailout.printStackTrace(TTY.out); - } - } catch (Throwable t) { - if (PrintStackTraceOnException.getValue() || ExitVMOnException.getValue()) { - t.printStackTrace(TTY.out); - } - - // Log a failure event. - CompilerFailureEvent event = eventProvider.newCompilerFailureEvent(); - if (event.shouldWrite()) { - event.setCompileId(getId()); - event.setMessage(t.getMessage()); - event.commit(); - } - - if (ExitVMOnException.getValue()) { - System.exit(-1); - } - } finally { - int compiledBytecodes = 0; - int codeSize = 0; - if (result != null) { - compiledBytecodes = result.getBytecodeSize(); - } - if (installedCode != null) { - codeSize = installedCode.getSize(); - } - CompiledBytecodes.add(compiledBytecodes); - - // Log a compilation event. - if (compilationEvent.shouldWrite()) { - compilationEvent.setMethod(method.format("%H.%n(%p)")); - compilationEvent.setCompileId(getId()); - compilationEvent.setCompileLevel(config.compilationLevelFullOptimization); - compilationEvent.setSucceeded(result != null && installedCode != null); - compilationEvent.setIsOsr(isOSR); - compilationEvent.setCodeSize(codeSize); - compilationEvent.setInlinedBytes(compiledBytecodes); - compilationEvent.commit(); - } - - if (jvmciEnv != 0) { - long ctask = unsafe.getAddress(jvmciEnv + config.jvmciEnvTaskOffset); - assert ctask != 0L; - unsafe.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes); - } - long compilationTime = System.nanoTime() - startCompilationTime; - if ((config.ciTime || config.ciTimeEach) && installedCode != null) { - long timeUnitsPerSecond = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); - CompilerToVM c2vm = HotSpotJVMCIRuntime.runtime().getCompilerToVM(); - c2vm.notifyCompilationStatistics(id, method, entryBCI != Compiler.INVOCATION_ENTRY_BCI, compiledBytecodes, compilationTime, timeUnitsPerSecond, installedCode); - } - } - } - - /** - * Determines whether to disable method inlining recording for the method being compiled. - */ - private boolean mustRecordMethodInlining(HotSpotVMConfig config) { - if (config.ciTime || config.ciTimeEach || CompiledBytecodes.isEnabled()) { - return true; - } - if (jvmciEnv == 0 || unsafe.getByte(jvmciEnv + config.jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset) != 0) { - return true; - } - return false; - } - - private String getMethodDescription() { - return String.format("%-6d JVMCI %-70s %-45s %-50s %s", id, method.getDeclaringClass().getName(), method.getName(), method.getSignature().toMethodDescriptor(), - entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "(OSR@" + entryBCI + ") "); - } - - private InstalledCode installMethod(final CompilationResult compResult) { - final HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend().getCodeCache(); - InstalledCode installedCode = null; - try (Scope s = Debug.scope("CodeInstall", new DebugDumpScope(String.valueOf(id), true), codeCache, method)) { - installedCode = codeCache.installMethod(method, compResult, jvmciEnv, installAsDefault); - } catch (Throwable e) { - throw Debug.handle(e); - } - return installedCode; - } - - @Override - public String toString() { - return "Compilation[id=" + id + ", " + method.format("%H.%n(%p)") + (entryBCI == Compiler.INVOCATION_ENTRY_BCI ? "" : "@" + entryBCI) + "]"; - } - - /** - * Compiles a method to machine code. - */ - public static void compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) { - // Ensure a debug configuration for this thread is initialized - if (Debug.isEnabled() && DebugScope.getConfig() == null) { - DebugEnvironment.initialize(TTY.out); - } - - CompilationTask task = new CompilationTask(method, entryBCI, jvmciEnv, id, true); - try (DebugConfigScope dcs = Debug.setConfig(new TopLevelDebugConfig())) { - task.runCompilation(); - } - return; - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompileTheWorld.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,512 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.hotspot; - -import static jdk.internal.jvmci.compiler.Compiler.*; - -import java.io.*; -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.net.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; -import java.util.jar.*; -import java.util.stream.*; - -import jdk.internal.jvmci.compiler.Compiler; -import jdk.internal.jvmci.debug.*; -import jdk.internal.jvmci.hotspot.*; -import jdk.internal.jvmci.meta.*; -import jdk.internal.jvmci.options.*; -import jdk.internal.jvmci.options.OptionUtils.OptionConsumer; -import jdk.internal.jvmci.options.OptionValue.OverrideScope; -import jdk.internal.jvmci.runtime.*; - -import com.oracle.graal.compiler.*; -import com.oracle.graal.compiler.CompilerThreadFactory.DebugConfigAccess; -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.internal.*; - -import static com.oracle.graal.hotspot.CompileTheWorld.Options.*; - -/** - * This class implements compile-the-world functionality with JVMCI. - */ -public final class CompileTheWorld { - - /** - * Magic token to trigger reading files from the boot class path. - */ - public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path"; - - public static class Options { - // @formatter:off - @Option(help = "Compile all methods in all classes on given class path", type = OptionType.Debug) - public static final OptionValue CompileTheWorldClasspath = new OptionValue<>(SUN_BOOT_CLASS_PATH); - @Option(help = "Verbose CompileTheWorld operation", type = OptionType.Debug) - public static final OptionValue CompileTheWorldVerbose = new OptionValue<>(true); - @Option(help = "The number of CompileTheWorld iterations to perform", type = OptionType.Debug) - public static final OptionValue CompileTheWorldIterations = new OptionValue<>(1); - @Option(help = "Only compile methods matching this filter", type = OptionType.Debug) - public static final OptionValue CompileTheWorldMethodFilter = new OptionValue<>(null); - @Option(help = "Exclude methods matching this filter from compilation", type = OptionType.Debug) - public static final OptionValue CompileTheWorldExcludeMethodFilter = new OptionValue<>(null); - @Option(help = "First class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) - public static final OptionValue CompileTheWorldStartAt = new OptionValue<>(1); - @Option(help = "Last class to consider when using -XX:+CompileTheWorld", type = OptionType.Debug) - public static final OptionValue CompileTheWorldStopAt = new OptionValue<>(Integer.MAX_VALUE); - @Option(help = "Option value overrides to use during compile the world. For example, " + - "to disable inlining and partial escape analysis specify '-PartialEscapeAnalysis -Inline'. " + - "The format for each option is the same as on the command line just without the '-G:' prefix.", type = OptionType.Debug) - public static final OptionValue CompileTheWorldConfig = new OptionValue<>(null); - - @Option(help = "Run CTW using as many threads as there are processors on the system", type = OptionType.Debug) - public static final OptionValue CompileTheWorldMultiThreaded = new OptionValue<>(false); - @Option(help = "Number of threads to use for multithreaded CTW. Defaults to Runtime.getRuntime().availableProcessors()", type = OptionType.Debug) - public static final OptionValue CompileTheWorldThreads = new OptionValue<>(0); - // @formatter:on - - /** - * Overrides {@link #CompileTheWorldStartAt} and {@link #CompileTheWorldStopAt} from - * {@code -XX} HotSpot options of the same name if the latter have non-default values. - */ - public static void overrideWithNativeOptions(HotSpotVMConfig c) { - if (c.compileTheWorldStartAt != 1) { - CompileTheWorldStartAt.setValue(c.compileTheWorldStartAt); - } - if (c.compileTheWorldStopAt != Integer.MAX_VALUE) { - CompileTheWorldStopAt.setValue(c.compileTheWorldStopAt); - } - } - } - - /** - * A mechanism for overriding JVMCI options that affect compilation. A {@link Config} object - * should be used in a try-with-resources statement to ensure overriding of options is scoped - * properly. For example: - * - *
-     *     Config config = ...;
-     *     try (AutoCloseable s = config == null ? null : config.apply()) {
-     *         // perform a JVMCI compilation
-     *     }
-     * 
- */ - @SuppressWarnings("serial") - public static class Config extends HashMap, Object> implements OptionConsumer { - /** - * Creates a {@link Config} object by parsing a set of space separated override options. - * - * @param options a space separated set of option value settings with each option setting in - * a format compatible with - * {@link OptionUtils#parseOption(String, OptionConsumer)}. Ignored if null. - */ - public Config(String options) { - if (options != null) { - for (String option : options.split("\\s+")) { - OptionUtils.parseOption(option, this); - } - } - } - - /** - * Applies the overrides represented by this object. The overrides are in effect until - * {@link OverrideScope#close()} is called on the returned object. - */ - OverrideScope apply() { - return OptionValue.override(this); - } - - public void set(OptionDescriptor desc, Object value) { - put(desc.getOptionValue(), value); - } - } - - /** List of Zip/Jar files to compile (see {@link Options#CompileTheWorldClasspath}). */ - private final String files; - - /** Class index to start compilation at (see {@link Options#CompileTheWorldStartAt}). */ - private final int startAt; - - /** Class index to stop compilation at (see {@link Options#CompileTheWorldStopAt}). */ - private final int stopAt; - - /** Only compile methods matching one of the filters in this array if the array is non-null. */ - private final MethodFilter[] methodFilters; - - /** Exclude methods matching one of the filters in this array if the array is non-null. */ - private final MethodFilter[] excludeMethodFilters; - - // Counters - private int classFileCounter = 0; - private AtomicLong compiledMethodsCounter = new AtomicLong(); - private AtomicLong compileTime = new AtomicLong(); - private AtomicLong memoryUsed = new AtomicLong(); - - private boolean verbose; - private final Config config; - - /** - * Signal that the threads should start compiling in multithreaded mode. - */ - private boolean running; - - private ThreadPoolExecutor threadPool; - - /** - * Creates a compile-the-world instance. - * - * @param files {@link File#pathSeparator} separated list of Zip/Jar files to compile - * @param startAt index of the class file to start compilation at - * @param stopAt index of the class file to stop compilation at - * @param methodFilters - * @param excludeMethodFilters - */ - public CompileTheWorld(String files, Config config, int startAt, int stopAt, String methodFilters, String excludeMethodFilters, boolean verbose) { - this.files = files; - this.startAt = startAt; - this.stopAt = stopAt; - this.methodFilters = methodFilters == null || methodFilters.isEmpty() ? null : MethodFilter.parse(methodFilters); - this.excludeMethodFilters = excludeMethodFilters == null || excludeMethodFilters.isEmpty() ? null : MethodFilter.parse(excludeMethodFilters); - this.verbose = verbose; - this.config = config; - - // We don't want the VM to exit when a method fails to compile... - config.putIfAbsent(ExitVMOnException, false); - - // ...but we want to see exceptions. - config.putIfAbsent(PrintBailout, true); - config.putIfAbsent(PrintStackTraceOnException, true); - config.putIfAbsent(HotSpotResolvedJavaMethodImpl.Options.UseProfilingInformation, false); - } - - public CompileTheWorld() { - this(CompileTheWorldClasspath.getValue(), new Config(CompileTheWorldConfig.getValue()), CompileTheWorldStartAt.getValue(), CompileTheWorldStopAt.getValue(), - CompileTheWorldMethodFilter.getValue(), CompileTheWorldExcludeMethodFilter.getValue(), CompileTheWorldVerbose.getValue()); - } - - /** - * Compiles all methods in all classes in the Zip/Jar archive files in - * {@link Options#CompileTheWorldClasspath}. If {@link Options#CompileTheWorldClasspath} - * contains the magic token {@link #SUN_BOOT_CLASS_PATH} passed up from HotSpot we take the - * files from the boot class path. - */ - public void compile() throws Throwable { - // By default only report statistics for the CTW threads themselves - if (JVMCIDebugConfig.DebugValueThreadFilter.hasDefaultValue()) { - JVMCIDebugConfig.DebugValueThreadFilter.setValue("^CompileTheWorld"); - } - - if (SUN_BOOT_CLASS_PATH.equals(files)) { - final String[] entries = System.getProperty(SUN_BOOT_CLASS_PATH).split(File.pathSeparator); - String bcpFiles = ""; - for (int i = 0; i < entries.length; i++) { - final String entry = entries[i]; - - // We stop at rt.jar, unless it is the first boot class path entry. - if (entry.endsWith("rt.jar") && (i > 0)) { - break; - } - if (i > 0) { - bcpFiles += File.pathSeparator; - } - bcpFiles += entry; - } - compile(bcpFiles); - } else { - compile(files); - } - } - - public void println() { - println(""); - } - - public void println(String format, Object... args) { - println(String.format(format, args)); - } - - public void println(String s) { - if (verbose) { - TTY.println(s); - } - } - - @SuppressWarnings("unused") - private static void dummy() { - } - - /** - * Compiles all methods in all classes in the Zip/Jar files passed. - * - * @param fileList {@link File#pathSeparator} separated list of Zip/Jar files to compile - * @throws IOException - */ - private void compile(String fileList) throws IOException { - final String[] entries = fileList.split(File.pathSeparator); - long start = System.currentTimeMillis(); - - CompilerThreadFactory factory = new CompilerThreadFactory("CompileTheWorld", new DebugConfigAccess() { - public JVMCIDebugConfig getDebugConfig() { - if (Debug.isEnabled() && DebugScope.getConfig() == null) { - return DebugEnvironment.initialize(System.out); - } - return null; - } - }); - - try { - // compile dummy method to get compiler initilized outside of the config debug override. - HotSpotResolvedJavaMethod dummyMethod = (HotSpotResolvedJavaMethod) JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess().lookupJavaMethod( - CompileTheWorld.class.getDeclaredMethod("dummy")); - CompilationTask task = new CompilationTask(dummyMethod, Compiler.INVOCATION_ENTRY_BCI, 0L, dummyMethod.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); - task.runCompilation(); - } catch (NoSuchMethodException | SecurityException e1) { - e1.printStackTrace(); - } - - /* - * Always use a thread pool, even for single threaded mode since it simplifies the use of - * DebugValueThreadFilter to filter on the thread names. - */ - int threadCount = 1; - if (Options.CompileTheWorldMultiThreaded.getValue()) { - threadCount = Options.CompileTheWorldThreads.getValue(); - if (threadCount == 0) { - threadCount = Runtime.getRuntime().availableProcessors(); - } - } else { - running = true; - } - threadPool = new ThreadPoolExecutor(threadCount, threadCount, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), factory); - - try (OverrideScope s = config.apply()) { - for (int i = 0; i < entries.length; i++) { - final String entry = entries[i]; - - // For now we only compile all methods in all classes in zip/jar files. - if (!entry.endsWith(".zip") && !entry.endsWith(".jar")) { - println("CompileTheWorld : Skipped classes in " + entry); - println(); - continue; - } - - if (methodFilters == null || methodFilters.length == 0) { - println("CompileTheWorld : Compiling all classes in " + entry); - } else { - String include = Arrays.asList(methodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", ")); - println("CompileTheWorld : Compiling all methods in " + entry + " matching one of the following filters: " + include); - } - if (excludeMethodFilters != null && excludeMethodFilters.length > 0) { - String exclude = Arrays.asList(excludeMethodFilters).stream().map(MethodFilter::toString).collect(Collectors.joining(", ")); - println("CompileTheWorld : Excluding all methods matching one of the following filters: " + exclude); - } - println(); - - URL url = new URL("jar", "", "file:" + entry + "!/"); - ClassLoader loader = new URLClassLoader(new URL[]{url}); - - JarFile jarFile = new JarFile(entry); - Enumeration e = jarFile.entries(); - - while (e.hasMoreElements()) { - JarEntry je = e.nextElement(); - if (je.isDirectory() || !je.getName().endsWith(".class")) { - continue; - } - - // Are we done? - if (classFileCounter >= stopAt) { - break; - } - - String className = je.getName().substring(0, je.getName().length() - ".class".length()); - String dottedClassName = className.replace('/', '.'); - classFileCounter++; - - if (methodFilters != null && !MethodFilter.matchesClassName(methodFilters, dottedClassName)) { - continue; - } - if (excludeMethodFilters != null && MethodFilter.matchesClassName(excludeMethodFilters, dottedClassName)) { - continue; - } - - if (dottedClassName.startsWith("jdk.management.") || dottedClassName.startsWith("jdk.internal.cmm.*")) { - continue; - } - - try { - // Load and initialize class - Class javaClass = Class.forName(dottedClassName, true, loader); - - // Pre-load all classes in the constant pool. - try { - HotSpotResolvedObjectType objectType = HotSpotResolvedObjectTypeImpl.fromObjectClass(javaClass); - ConstantPool constantPool = objectType.constantPool(); - for (int cpi = 1; cpi < constantPool.length(); cpi++) { - constantPool.loadReferencedType(cpi, HotSpotConstantPool.Bytecodes.LDC); - } - } catch (Throwable t) { - // If something went wrong during pre-loading we just ignore it. - println("Preloading failed for (%d) %s: %s", classFileCounter, className, t); - } - - // Are we compiling this class? - MetaAccessProvider metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); - if (classFileCounter >= startAt) { - println("CompileTheWorld (%d) : %s", classFileCounter, className); - - // Compile each constructor/method in the class. - for (Constructor constructor : javaClass.getDeclaredConstructors()) { - HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(constructor); - if (canBeCompiled(javaMethod, constructor.getModifiers())) { - compileMethod(javaMethod); - } - } - for (Method method : javaClass.getDeclaredMethods()) { - HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method); - if (canBeCompiled(javaMethod, method.getModifiers())) { - compileMethod(javaMethod); - } - } - } - } catch (Throwable t) { - println("CompileTheWorld (%d) : Skipping %s %s", classFileCounter, className, t.toString()); - t.printStackTrace(); - } - } - jarFile.close(); - } - } - - if (!running) { - startThreads(); - } - int wakeups = 0; - while (threadPool.getCompletedTaskCount() != threadPool.getTaskCount()) { - if (wakeups % 15 == 0) { - TTY.println("CompileTheWorld : Waiting for " + (threadPool.getTaskCount() - threadPool.getCompletedTaskCount()) + " compiles"); - } - try { - threadPool.awaitTermination(1, TimeUnit.SECONDS); - wakeups++; - } catch (InterruptedException e) { - } - } - threadPool = null; - - long elapsedTime = System.currentTimeMillis() - start; - - println(); - if (Options.CompileTheWorldMultiThreaded.getValue()) { - TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms elapsed, %d ms compile time, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), elapsedTime, - compileTime.get(), memoryUsed.get()); - } else { - TTY.println("CompileTheWorld : Done (%d classes, %d methods, %d ms, %d bytes of memory used)", classFileCounter, compiledMethodsCounter.get(), compileTime.get(), memoryUsed.get()); - } - } - - private synchronized void startThreads() { - running = true; - // Wake up any waiting threads - notifyAll(); - } - - private synchronized void waitToRun() { - while (!running) { - try { - wait(); - } catch (InterruptedException e) { - } - } - } - - private void compileMethod(HotSpotResolvedJavaMethod method) throws InterruptedException, ExecutionException { - if (methodFilters != null && !MethodFilter.matches(methodFilters, method)) { - return; - } - if (excludeMethodFilters != null && MethodFilter.matches(excludeMethodFilters, method)) { - return; - } - Future task = threadPool.submit(new Runnable() { - public void run() { - waitToRun(); - try (OverrideScope s = config.apply()) { - compileMethod(method, classFileCounter); - } - } - }); - if (threadPool.getCorePoolSize() == 1) { - task.get(); - } - } - - /** - * Compiles a method and gathers some statistics. - */ - private void compileMethod(HotSpotResolvedJavaMethod method, int counter) { - try { - long start = System.currentTimeMillis(); - long allocatedAtStart = MemUseTrackerImpl.getCurrentThreadAllocatedBytes(); - - CompilationTask task = new CompilationTask(method, Compiler.INVOCATION_ENTRY_BCI, 0L, method.allocateCompileId(Compiler.INVOCATION_ENTRY_BCI), false); - task.runCompilation(); - - memoryUsed.getAndAdd(MemUseTrackerImpl.getCurrentThreadAllocatedBytes() - allocatedAtStart); - compileTime.getAndAdd(System.currentTimeMillis() - start); - compiledMethodsCounter.incrementAndGet(); - } catch (Throwable t) { - // Catch everything and print a message - println("CompileTheWorld (%d) : Error compiling method: %s", counter, method.format("%H.%n(%p):%r")); - t.printStackTrace(TTY.out); - } - } - - /** - * Determines if a method should be compiled (Cf. CompilationPolicy::can_be_compiled). - * - * @return true if it can be compiled, false otherwise - */ - private static boolean canBeCompiled(HotSpotResolvedJavaMethod javaMethod, int modifiers) { - if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { - return false; - } - HotSpotVMConfig c = HotSpotJVMCIRuntime.runtime().getConfig(); - if (c.dontCompileHugeMethods && javaMethod.getCodeSize() > c.hugeMethodLimit) { - return false; - } - // Allow use of -XX:CompileCommand=dontinline to exclude problematic methods - if (!javaMethod.canBeInlined()) { - return false; - } - // Skip @Snippets for now - for (Annotation annotation : javaMethod.getAnnotations()) { - if (annotation.annotationType().getName().equals("com.oracle.graal.replacements.Snippet")) { - return false; - } - } - return true; - } - -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/backend/ConstantPhiTest.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/backend/ConstantPhiTest.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.jtt.backend; - -import static com.oracle.graal.api.directives.GraalDirectives.*; - -import java.lang.reflect.*; - -import jdk.internal.jvmci.options.*; -import jdk.internal.jvmci.options.OptionValue.OverrideScope; - -import org.junit.*; - -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.jtt.*; - -public class ConstantPhiTest extends JTTTest { - - public static int test(int i, int x) throws Throwable { - int r; - if (injectBranchProbability(LIKELY_PROBABILITY, i < 0)) { - r = 42; - } else { - r = x; - } - destroyCallerSavedValues(); - return r; - } - - protected static void destroyCallerSavedValues() throws Throwable { - Class c = ConstantPhiTest.class; - Method m = c.getMethod("destroyCallerSavedValues0"); - m.invoke(null); - } - - public static void destroyCallerSavedValues0() { - } - - @Test - public void run0() { - try (OverrideScope os = OptionValue.override(GraalOptions.MaximumInliningSize, -1)) { - runTest("test", 0, 0xDEADDEAD); - } - } - - @Test - public void run1() { - try (OverrideScope os = OptionValue.override(GraalOptions.MaximumInliningSize, -1)) { - runTest("test", -1, 0xDEADDEAD); - } - } - - @Test - public void run2() { - try (OverrideScope os = OptionValue.override(GraalOptions.MaximumInliningSize, -1)) { - runTest("test", 1, 0xDEADDEAD); - } - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BlockEndOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64BlockEndOp.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.lir.amd64; - -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.*; -import com.oracle.graal.lir.asm.*; - -public abstract class AMD64BlockEndOp extends AbstractBlockEndOp { - - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(AMD64BlockEndOp.class); - - protected AMD64BlockEndOp(LIRInstructionClass c) { - super(c); - } - - @Override - public final void emitCode(CompilationResultBuilder crb) { - emitCode(crb, (AMD64MacroAssembler) crb.asm); - } - - public abstract void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm); -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBlockEndOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBlockEndOp.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.lir.sparc; - -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.*; - -import jdk.internal.jvmci.meta.*; - -public abstract class SPARCBlockEndOp extends SPARCLIRInstruction implements BlockEndOp { - public static final LIRInstructionClass TYPE = LIRInstructionClass.create(SPARCBlockEndOp.class); - - @Alive({REG, STACK, CONST}) private Value[] outgoingValues; - private int size; - - protected SPARCBlockEndOp(LIRInstructionClass c) { - this(c, null); - } - - protected SPARCBlockEndOp(LIRInstructionClass c, SizeEstimate sizeEstimate) { - super(c, sizeEstimate); - this.outgoingValues = Value.NO_VALUES; - this.size = 0; - } - - public void setOutgoingValues(Value[] values) { - assert outgoingValues.length == 0; - assert values != null; - outgoingValues = values; - size = values.length; - } - - public int getOutgoingSize() { - return size; - } - - public Value getOutgoingValue(int idx) { - assert checkRange(idx); - return outgoingValues[idx]; - } - - private boolean checkRange(int idx) { - return idx < size; - } - - public void clearOutgoingValues() { - outgoingValues = Value.NO_VALUES; - size = 0; - } - - public int addOutgoingValues(Value[] v) { - - int t = size + v.length; - if (t >= outgoingValues.length) { - Value[] newArray = new Value[t]; - System.arraycopy(outgoingValues, 0, newArray, 0, size); - outgoingValues = newArray; - } - System.arraycopy(v, 0, outgoingValues, size, v.length); - size = t; - return t; - - } -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ArithmeticOperation.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ArithmeticOperation.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.nodes; - -/** - * An {@code ArithmeticOperation} is an operation that does primitive value arithmetic without side - * effect. - */ -public interface ArithmeticOperation { -} diff -r 2c87ecb88c81 -r cd04ef3c7c49 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/TypeCheckHints.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/TypeCheckHints.java Fri Jul 24 02:11:18 2015 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.nodes; - -import java.util.*; - -import jdk.internal.jvmci.meta.*; -import jdk.internal.jvmci.meta.Assumptions.*; -import jdk.internal.jvmci.meta.JavaTypeProfile.*; - -/** - * Utility for deriving hint types for a type check instruction (e.g. checkcast or instanceof) based - * on the target type of the check and any profiling information available for the instruction. - */ -public class TypeCheckHints { - - /** - * A receiver type profiled in a type check instruction. - */ - public static class Hint { - - /** - * A type seen while profiling a type check instruction. - */ - public final ResolvedJavaType type; - - /** - * Specifies if {@link #type} is a sub-type of the checked type. - */ - public final boolean positive; - - Hint(ResolvedJavaType type, boolean positive) { - this.type = type; - this.positive = positive; - } - } - - private static final Hint[] NO_HINTS = {}; - - /** - * If non-null, then this is the only type that could pass the type check because the target of - * the type check is a final class or has been speculated to be a final class and this value is - * the only concrete subclass of the target type. - */ - public final ResolvedJavaType exact; - - /** - * The most likely types that the type check instruction will see. - */ - public final Hint[] hints; - - /** - * The profile from which this information was derived. - */ - public final JavaTypeProfile profile; - - /** - * The total probability that the type check will hit one of the types in {@link #hints}. - */ - public final double hintHitProbability; - - /** - * Derives hint information for use when generating the code for a type check instruction. - * - * @param targetType the target type of the type check - * @param profile the profiling information available for the instruction (if any) - * @param assumptions the object in which speculations are recorded. This is null if - * speculations are not supported. - * @param minHintHitProbability if the probability that the type check will hit one of the - * profiled types (up to {@code maxHints}) is below this value, then {@link #hints} - * will be null - * @param maxHints the maximum length of {@link #hints} - */ - public TypeCheckHints(ResolvedJavaType targetType, JavaTypeProfile profile, Assumptions assumptions, double minHintHitProbability, int maxHints) { - this.profile = profile; - if (targetType != null && targetType.isLeaf()) { - exact = targetType; - } else { - if (assumptions != null) { - AssumptionResult leafConcreteSubtype = targetType == null ? null : targetType.findLeafConcreteSubtype(); - if (leafConcreteSubtype != null) { - assumptions.record(leafConcreteSubtype); - exact = leafConcreteSubtype.getResult(); - } else { - exact = null; - } - } else { - exact = null; - } - } - Double[] hitProbability = {null}; - this.hints = makeHints(targetType, profile, minHintHitProbability, maxHints, hitProbability); - this.hintHitProbability = hitProbability[0]; - } - - private static Hint[] makeHints(ResolvedJavaType targetType, JavaTypeProfile profile, double minHintHitProbability, int maxHints, Double[] hitProbability) { - double hitProb = 0.0d; - Hint[] hintsBuf = NO_HINTS; - if (profile != null) { - double notRecordedTypes = profile.getNotRecordedProbability(); - ProfiledType[] ptypes = profile.getTypes(); - if (notRecordedTypes < (1D - minHintHitProbability) && ptypes != null && ptypes.length > 0) { - hintsBuf = new Hint[ptypes.length]; - int hintCount = 0; - for (ProfiledType ptype : ptypes) { - if (targetType != null) { - ResolvedJavaType hintType = ptype.getType(); - hintsBuf[hintCount++] = new Hint(hintType, targetType.isAssignableFrom(hintType)); - hitProb += ptype.getProbability(); - } - if (hintCount == maxHints) { - break; - } - } - if (hitProb >= minHintHitProbability) { - if (hintsBuf.length != hintCount || hintCount > maxHints) { - hintsBuf = Arrays.copyOf(hintsBuf, Math.min(maxHints, hintCount)); - } - } else { - hintsBuf = NO_HINTS; - hitProb = 0.0d; - } - } - } - hitProbability[0] = hitProb; - return hintsBuf; - } -}