# HG changeset patch # User Doug Simon # Date 1401808432 -7200 # Node ID 76f40e11c82075aef5306af2adff651f44905a73 # Parent 23ae0cbcb2ae7bd5958e9c6135aed23ae824aeee refactored HotSpotGraalRuntime.LogFileOption to PrintStreamOption to workaround a javac bug as well as to clarify its design diff -r 23ae0cbcb2ae -r 76f40e11c820 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationQueue.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationQueue.java Tue Jun 03 17:11:40 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationQueue.java Tue Jun 03 17:13:52 2014 +0200 @@ -119,7 +119,7 @@ private CompilationQueue() { CompilerThreadFactory factory = new CompilerThreadFactory("GraalCompilerThread", new DebugConfigAccess() { public GraalDebugConfig getDebugConfig() { - return Debug.isEnabled() ? DebugEnvironment.initialize(HotSpotGraalRuntime.Options.LogFile.log()) : null; + return Debug.isEnabled() ? DebugEnvironment.initialize(HotSpotGraalRuntime.Options.LogFile.getStream()) : null; } }); diff -r 23ae0cbcb2ae -r 76f40e11c820 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Jun 03 17:11:40 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Jun 03 17:13:52 2014 +0200 @@ -25,13 +25,11 @@ import static com.oracle.graal.compiler.GraalDebugConfig.*; import static com.oracle.graal.compiler.common.GraalOptions.*; import static com.oracle.graal.compiler.common.UnsafeAccess.*; -//import static com.oracle.graal.hotspot.CompilationQueue.*; import static com.oracle.graal.hotspot.CompileTheWorld.Options.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.Options.*; import static com.oracle.graal.hotspot.InitTimer.*; import static sun.reflect.Reflection.*; -import java.io.*; import java.lang.reflect.*; import java.util.*; @@ -124,7 +122,7 @@ this.compilerToVm = toVM; - TTY.initialize(Options.LogFile.log()); + TTY.initialize(Options.LogFile.getStream()); if (Log.getValue() == null && Meter.getValue() == null && Time.getValue() == null && Dump.getValue() == null) { if (MethodFilter.getValue() != null) { @@ -133,7 +131,7 @@ } if (Debug.isEnabled()) { - DebugEnvironment.initialize(LogFile.log()); + DebugEnvironment.initialize(LogFile.getStream()); String summary = DebugValueSummary.getValue(); if (summary != null) { @@ -176,38 +174,10 @@ static final OptionValue GraalRuntime = new OptionValue<>(""); @Option(help = "File to which logging is sent") - public static final LogFileOption LogFile = new LogFileOption(); + public static final PrintStreamOption LogFile = new PrintStreamOption(); // @formatter:on } - public static class LogFileOption extends OptionValue { - public LogFileOption() { - super(null); - } - - private volatile PrintStream log; - - public PrintStream log() { - if (log == null) { - if (getValue() != null) { - synchronized (this) { - if (log == null) { - try { - final boolean enableAutoflush = true; - log = new PrintStream(new FileOutputStream(LogFile.getValue()), enableAutoflush); - } catch (FileNotFoundException e) { - throw new RuntimeException("couldn't open log file: " + LogFile.getValue(), e); - } - } - } - } else { - log = System.out; - } - } - return log; - } - } - private static HotSpotBackendFactory findFactory(String architecture) { HotSpotBackendFactory basic = null; HotSpotBackendFactory selected = null; diff -r 23ae0cbcb2ae -r 76f40e11c820 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/PrintStreamOption.java Tue Jun 03 17:13:52 2014 +0200 @@ -0,0 +1,81 @@ +/* + * 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.hotspot; + +import java.io.*; + +import com.oracle.graal.options.*; + +/** + * An option that encapsulates and configures a print stream. + */ +public class PrintStreamOption extends OptionValue { + + public PrintStreamOption() { + super(null); + } + + /** + * The print stream to which output will be written. + * + * Declared {@code volatile} to enable safe use of double-checked locking in + * {@link #getStream()} and {@link #setValue(Object)}. + */ + private volatile PrintStream ps; + + /** + * Gets the print stream configured by this option. + */ + public PrintStream getStream() { + if (ps == null) { + if (getValue() != null) { + synchronized (this) { + if (ps == null) { + try { + final boolean enableAutoflush = true; + ps = new PrintStream(new FileOutputStream(getValue()), enableAutoflush); + } catch (FileNotFoundException e) { + throw new RuntimeException("couldn't open file: " + getValue(), e); + } + } + } + } else { + ps = System.out; + } + } + return ps; + } + + @Override + public void setValue(Object v) { + if (ps != null) { + synchronized (this) { + if (ps != null) { + ps.close(); + ps = null; + } + } + } + super.setValue(v); + } +} \ No newline at end of file