1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.debug; 24 25 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.Dump; 26 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.Log; 27 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.Count; 28 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.MethodFilter; 29 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.Time; 30 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.TrackMemUse; 31 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.Verify; 32 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.MethodMeter; 33 34 import java.io.PrintStream; 35 import java.util.ArrayList; 36 import java.util.List; 37 38 import org.graalvm.compiler.serviceprovider.GraalServices; 39 40 import jdk.vm.ci.runtime.JVMCI; 41 42 public class DebugEnvironment { 43 44 public static GraalDebugConfig initialize(PrintStream log, Object... extraArgs) { 45 // Initialize JVMCI before loading class Debug 46 JVMCI.initialize(); 47 if (!Debug.isEnabled()) { 48 log.println("WARNING: Scope debugging needs to be enabled with -esa"); 49 return null; 50 } 51 List<DebugDumpHandler> dumpHandlers = new ArrayList<>(); 52 List<DebugVerifyHandler> verifyHandlers = new ArrayList<>(); 53 GraalDebugConfig debugConfig = new GraalDebugConfig(Log.getValue(), Count.getValue(), TrackMemUse.getValue(), Time.getValue(), Dump.getValue(), Verify.getValue(), MethodFilter.getValue(), 54 MethodMeter.getValue(), 55 log, dumpHandlers, verifyHandlers); 56 57 for (DebugConfigCustomizer customizer : GraalServices.load(DebugConfigCustomizer.class)) { 58 customizer.customize(debugConfig, extraArgs); 59 } 60 61 Debug.setConfig(debugConfig); 62 return debugConfig; 63 } 64 }