changeset 22486:6292599feb75

Move PrintStreamOption out of JVMCI
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Fri, 28 Aug 2015 17:18:18 -0700
parents fc0a5a73fa56
children a0e5714d5436
files jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/PrintStreamOption.java
diffstat 2 files changed, 0 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java	Fri Aug 28 14:39:05 2015 -0700
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java	Fri Aug 28 17:18:18 2015 -0700
@@ -32,7 +32,6 @@
 import jdk.internal.jvmci.compiler.Compiler;
 import jdk.internal.jvmci.inittimer.*;
 import jdk.internal.jvmci.meta.*;
-import jdk.internal.jvmci.options.*;
 import jdk.internal.jvmci.runtime.*;
 import jdk.internal.jvmci.service.*;
 
@@ -105,14 +104,6 @@
         this.compilerToVm = toVM;
     }
 
-    public static class Options {
-
-        // @formatter:off
-        @Option(help = "File to which logging is sent.  A %p in the name will be replaced with a string identifying the process, usually the process id.", type = OptionType.Expert)
-        public static final PrintStreamOption LogFile = new PrintStreamOption();
-        // @formatter:on
-    }
-
     public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
         for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
             if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/PrintStreamOption.java	Fri Aug 28 14:39:05 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,146 +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 jdk.internal.jvmci.hotspot;
-
-import java.io.*;
-import java.lang.management.*;
-
-import jdk.internal.jvmci.options.*;
-
-/**
- * An option that encapsulates and configures a print stream.
- */
-public class PrintStreamOption extends OptionValue<String> {
-
-    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;
-
-    /**
-     * Replace any instance of %p with a an identifying name. Try to get it from the RuntimeMXBean
-     * name.
-     *
-     * @return the name of the file to log to
-     */
-    private String getFilename() {
-        String name = getValue();
-        if (name.contains("%p")) {
-            String runtimeName = ManagementFactory.getRuntimeMXBean().getName();
-            try {
-                int index = runtimeName.indexOf('@');
-                if (index != -1) {
-                    long pid = Long.parseLong(runtimeName.substring(0, index));
-                    runtimeName = Long.toString(pid);
-                }
-                name = name.replaceAll("%p", runtimeName);
-            } catch (NumberFormatException e) {
-
-            }
-        }
-        return name;
-    }
-
-    /**
-     * Gets the print stream configured by this option. If no file is configured, the print stream
-     * will output to {@link CompilerToVM#writeDebugOutput(byte[], int, int)}.
-     */
-    public PrintStream getStream() {
-        if (ps == null) {
-            if (getValue() != null) {
-                synchronized (this) {
-                    if (ps == null) {
-                        try {
-                            final boolean enableAutoflush = true;
-                            ps = new PrintStream(new FileOutputStream(getFilename()), enableAutoflush);
-                            /* Add the JVM and Java arguments to the log file to help identity it. */
-                            String inputArguments = String.join(" ", ManagementFactory.getRuntimeMXBean().getInputArguments());
-                            ps.println("VM Arguments: " + inputArguments);
-                            String cmd = System.getProperty("sun.java.command");
-                            if (cmd != null) {
-                                ps.println("sun.java.command=" + cmd);
-                            }
-                        } catch (FileNotFoundException e) {
-                            throw new RuntimeException("couldn't open file: " + getValue(), e);
-                        }
-                    }
-                }
-            } else {
-                OutputStream ttyOut = new OutputStream() {
-                    CompilerToVM vm;
-
-                    private CompilerToVM vm() {
-                        if (vm == null) {
-                            vm = HotSpotJVMCIRuntime.runtime().getCompilerToVM();
-                        }
-                        return vm;
-                    }
-
-                    @Override
-                    public void write(byte[] b, int off, int len) throws IOException {
-                        if (b == null) {
-                            throw new NullPointerException();
-                        } else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) {
-                            throw new IndexOutOfBoundsException();
-                        } else if (len == 0) {
-                            return;
-                        }
-                        vm().writeDebugOutput(b, off, len);
-                    }
-
-                    @Override
-                    public void write(int b) throws IOException {
-                        write(new byte[]{(byte) b}, 0, 1);
-                    }
-
-                    @Override
-                    public void flush() throws IOException {
-                        vm().flushDebugOutput();
-                    }
-                };
-                ps = new PrintStream(ttyOut);
-            }
-        }
-        return ps;
-    }
-
-    @Override
-    public void setValue(Object v) {
-        if (ps != null) {
-            synchronized (this) {
-                if (ps != null) {
-                    ps.close();
-                    ps = null;
-                }
-            }
-        }
-        super.setValue(v);
-    }
-}