changeset 18690:abcff66a23b0

Add ability to programmatically set the dump level
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Mon, 15 Dec 2014 16:00:14 -0800
parents 8923610115c9
children 3f38534e9a10
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/TopLevelDebugConfig.java graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java
diffstat 3 files changed, 87 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/TopLevelDebugConfig.java	Mon Dec 15 16:00:14 2014 -0800
@@ -0,0 +1,31 @@
+/*
+ * 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 {
+}
--- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Mon Dec 15 13:10:44 2014 -0800
+++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugScope.java	Mon Dec 15 16:00:14 2014 -0800
@@ -169,6 +169,58 @@
         return currentDumpLevel >= dumpLevel;
     }
 
+    /**
+     * Enable dumping at the new {@code dumpLevel} for remainder of compile. Requires a
+     * TopLevelDebugConfig
+     *
+     * @param dumpLevel
+     */
+    public static void setDumpLevel(int dumpLevel) {
+        TopLevelDebugConfig config = fetchTopLevelDebugConfig("setLogLevel");
+        if (config != null) {
+            config.override(DelegatingDebugConfig.Level.DUMP, dumpLevel);
+            recursiveUpdateFlags();
+        }
+    }
+
+    /**
+     * Enable logging at the new {@code logLevel} for remainder of compile. Requires a
+     * TopLevelDebugConfig
+     *
+     * @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 {
+            PrintStream out = System.out;
+            if (config == null) {
+                out.printf("DebugScope.%s ignored because debugging is disabled%n", msg);
+            } else {
+                out.printf("DebugScope.%s ignored because top level delegate config missing%n", msg);
+            }
+            return null;
+        }
+    }
+
     public boolean isVerifyEnabled() {
         return verifyEnabled;
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Mon Dec 15 13:10:44 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Mon Dec 15 16:00:14 2014 -0800
@@ -27,6 +27,7 @@
 import static com.oracle.graal.compiler.GraalCompiler.*;
 import static com.oracle.graal.compiler.common.GraalOptions.*;
 import static com.oracle.graal.compiler.common.UnsafeAccess.*;
+import static com.oracle.graal.debug.Debug.*;
 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
 import static com.oracle.graal.hotspot.InitTimer.*;
 import static com.oracle.graal.hotspot.meta.HotSpotSuitesProvider.*;
@@ -365,7 +366,9 @@
     static void compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long ctask, int id) {
         HotSpotBackend backend = runtime().getHostBackend();
         CompilationTask task = new CompilationTask(backend, method, entryBCI, ctask, id, true);
-        task.runCompilation();
+        try (DebugConfigScope dcs = setConfig(new TopLevelDebugConfig())) {
+            task.runCompilation();
+        }
         return;
     }
 }