hotspot/src/jdk.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java
author dnsimon
Tue, 10 May 2016 11:48:06 +0200
changeset 38666 5ff19807abd5
parent 38663 03fe0752bb2f
child 38674 eacc567feae8
permissions -rw-r--r--
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     1
/*
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 35570
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     4
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     8
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    13
 * accompanied this code).
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    14
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    18
 *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    21
 * questions.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    22
 */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    23
package jdk.vm.ci.hotspot;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    24
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    25
import static jdk.vm.ci.inittimer.InitTimer.timer;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    26
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    27
import java.io.IOException;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    28
import java.io.OutputStream;
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
    29
import java.io.PrintStream;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    30
import java.lang.reflect.Array;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    31
import java.lang.reflect.Field;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    32
import java.lang.reflect.Method;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    33
import java.lang.reflect.Modifier;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    34
import java.util.Collections;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    35
import java.util.HashMap;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    36
import java.util.Map;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    37
import java.util.Objects;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    38
import java.util.TreeMap;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    39
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    40
import jdk.vm.ci.code.Architecture;
35592
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35582
diff changeset
    41
import jdk.vm.ci.code.CompilationRequestResult;
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 35570
diff changeset
    42
import jdk.vm.ci.code.CompiledCode;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    43
import jdk.vm.ci.code.InstalledCode;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    44
import jdk.vm.ci.common.JVMCIError;
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
    45
import jdk.vm.ci.hotspot.services.HotSpotJVMCICompilerFactory;
38663
03fe0752bb2f 8155023: jdk.vm.ci needs to securely export services
dnsimon
parents: 36594
diff changeset
    46
import jdk.vm.ci.hotspot.services.HotSpotVMEventListener;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    47
import jdk.vm.ci.inittimer.InitTimer;
35837
7edbab7f12d0 8149019: remove redundant modifiers
dnsimon
parents: 35592
diff changeset
    48
import jdk.vm.ci.inittimer.SuppressFBWarnings;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    49
import jdk.vm.ci.meta.JVMCIMetaAccessContext;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    50
import jdk.vm.ci.meta.JavaKind;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    51
import jdk.vm.ci.meta.JavaType;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    52
import jdk.vm.ci.meta.ResolvedJavaType;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    53
import jdk.vm.ci.runtime.JVMCI;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    54
import jdk.vm.ci.runtime.JVMCIBackend;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    55
import jdk.vm.ci.runtime.JVMCICompiler;
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
    56
import jdk.vm.ci.runtime.services.JVMCICompilerFactory;
35564
3485bf43b924 8146364: Remove @ServiceProvider mechanism from JVMCI
dnsimon
parents: 35160
diff changeset
    57
import jdk.vm.ci.services.Services;
35234
854fc566323e 8146660: Resolve merge issue in resulting from sun.misc.VM move to jdk.internal.misc
amurillo
parents: 35160
diff changeset
    58
import jdk.internal.misc.VM;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    59
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    60
//JaCoCo Exclude
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    61
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    62
/**
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    63
 * HotSpot implementation of a JVMCI runtime.
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    64
 *
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    65
 * The initialization of this class is very fragile since it's initialized both through
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    66
 * {@link JVMCI#initialize()} or through calling {@link HotSpotJVMCIRuntime#runtime()} and
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    67
 * {@link HotSpotJVMCIRuntime#runtime()} is also called by {@link JVMCI#initialize()}. So this class
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    68
 * can't have a static initializer and any required initialization must be done as part of
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    69
 * {@link #runtime()}. This allows the initialization to funnel back through
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    70
 * {@link JVMCI#initialize()} without deadlocking.
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    71
 */
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    72
public final class HotSpotJVMCIRuntime implements HotSpotJVMCIRuntimeProvider, HotSpotProxified {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    73
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    74
    @SuppressWarnings("try")
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    75
    static class DelayedInit {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    76
        private static final HotSpotJVMCIRuntime instance;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    77
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    78
        static {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    79
            try (InitTimer t = timer("HotSpotJVMCIRuntime.<init>")) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    80
                instance = new HotSpotJVMCIRuntime();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    81
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    82
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    83
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    84
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    85
    /**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    86
     * Gets the singleton {@link HotSpotJVMCIRuntime} object.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    87
     */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    88
    public static HotSpotJVMCIRuntime runtime() {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
    89
        JVMCI.initialize();
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    90
        return DelayedInit.instance;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    91
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
    92
35160
acae4975b367 8146001: Remove support for command line options from JVMCI
dnsimon
parents: 33632
diff changeset
    93
    /**
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
    94
     * A list of all supported JVMCI options.
35160
acae4975b367 8146001: Remove support for command line options from JVMCI
dnsimon
parents: 33632
diff changeset
    95
     */
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
    96
    public enum Option {
36594
5a2cfca38c3d 8151470: [JVMCI] remove up-call to HotSpotJVMCICompilerConfig.selectCompiler
twisti
parents: 35837
diff changeset
    97
        Compiler(String.class, null, "Selects the system compiler."),
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
    98
        ImplicitStableValues(boolean.class, true, "Mark well-known stable fields as such."),
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
    99
        // Note: The following one is not used (see InitTimer.ENABLED).
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   100
        InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."),
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   101
        PrintConfig(boolean.class, false, "Prints all HotSpotVMConfig fields."),
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   102
        PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."),
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   103
        ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."),
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   104
        TraceMethodDataFilter(String.class, null, ""),
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   105
        TrustFinalDefaultFields(boolean.class, true, "Determines whether to treat final fields with default values as constant.");
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   106
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   107
        /**
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   108
         * The prefix for system properties that are JVMCI options.
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   109
         */
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   110
        private static final String JVMCI_OPTION_PROPERTY_PREFIX = "jvmci.";
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   111
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   112
        /**
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   113
         * Marker for uninitialized flags.
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   114
         */
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   115
        private static final String UNINITIALIZED = "UNINITIALIZED";
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   116
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   117
        private final Class<?> type;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   118
        private Object value;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   119
        private final Object defaultValue;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   120
        private boolean isDefault;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   121
        private final String help;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   122
35837
7edbab7f12d0 8149019: remove redundant modifiers
dnsimon
parents: 35592
diff changeset
   123
        Option(Class<?> type, Object defaultValue, String help) {
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   124
            assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name();
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   125
            this.type = type;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   126
            this.value = UNINITIALIZED;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   127
            this.defaultValue = defaultValue;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   128
            this.help = help;
35160
acae4975b367 8146001: Remove support for command line options from JVMCI
dnsimon
parents: 33632
diff changeset
   129
        }
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   130
35837
7edbab7f12d0 8149019: remove redundant modifiers
dnsimon
parents: 35592
diff changeset
   131
        @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "sentinel must be String since it's a static final in an enum")
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   132
        private Object getValue() {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   133
            if (value == UNINITIALIZED) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   134
                String propertyValue = VM.getSavedProperty(JVMCI_OPTION_PROPERTY_PREFIX + name());
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   135
                if (propertyValue == null) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   136
                    this.value = defaultValue;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   137
                    this.isDefault = true;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   138
                } else {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   139
                    if (type == boolean.class) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   140
                        this.value = Boolean.parseBoolean(propertyValue);
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   141
                    } else if (type == String.class) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   142
                        this.value = propertyValue;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   143
                    } else {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   144
                        throw new JVMCIError("Unexpected option type " + type);
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   145
                    }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   146
                    this.isDefault = false;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   147
                }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   148
                // Saved properties should not be interned - let's be sure
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   149
                assert value != UNINITIALIZED;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   150
            }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   151
            return value;
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   152
        }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   153
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   154
        /**
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   155
         * Returns the option's value as boolean.
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   156
         *
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   157
         * @return option's value
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   158
         */
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   159
        public boolean getBoolean() {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   160
            return (boolean) getValue();
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   161
        }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   162
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   163
        /**
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   164
         * Returns the option's value as String.
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   165
         *
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   166
         * @return option's value
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   167
         */
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   168
        public String getString() {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   169
            return (String) getValue();
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   170
        }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   171
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   172
        /**
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   173
         * Prints all option flags to {@code out}.
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   174
         *
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   175
         * @param out stream to print to
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   176
         */
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   177
        public static void printFlags(PrintStream out) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   178
            out.println("[List of JVMCI options]");
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   179
            for (Option option : values()) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   180
                Object value = option.getValue();
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   181
                String assign = option.isDefault ? ":=" : " =";
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   182
                out.printf("%9s %-40s %s %-14s %s%n", option.type.getSimpleName(), option, assign, value, option.help);
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   183
            }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   184
        }
35160
acae4975b367 8146001: Remove support for command line options from JVMCI
dnsimon
parents: 33632
diff changeset
   185
    }
acae4975b367 8146001: Remove support for command line options from JVMCI
dnsimon
parents: 33632
diff changeset
   186
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   187
    public static HotSpotJVMCIBackendFactory findFactory(String architecture) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   188
        for (HotSpotJVMCIBackendFactory factory : Services.load(HotSpotJVMCIBackendFactory.class)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   189
            if (factory.getArchitecture().equalsIgnoreCase(architecture)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   190
                return factory;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   191
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   192
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   193
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   194
        throw new JVMCIError("No JVMCI runtime available for the %s architecture", architecture);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   195
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   196
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   197
    /**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   198
     * Gets the kind of a word value on the {@linkplain #getHostJVMCIBackend() host} backend.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   199
     */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   200
    public static JavaKind getHostWordKind() {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   201
        return runtime().getHostJVMCIBackend().getCodeCache().getTarget().wordJavaKind;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   202
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   203
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   204
    protected final CompilerToVM compilerToVm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   205
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   206
    protected final HotSpotVMConfig config;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   207
    private final JVMCIBackend hostBackend;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   208
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   209
    private final JVMCICompilerFactory compilerFactory;
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   210
    private final HotSpotJVMCICompilerFactory hsCompilerFactory;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   211
    private volatile JVMCICompiler compiler;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   212
    protected final JVMCIMetaAccessContext metaAccessContext;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   213
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   214
    /**
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   215
     * Stores the result of {@link HotSpotJVMCICompilerFactory#getCompilationLevelAdjustment} so
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   216
     * that it can be read from the VM.
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   217
     */
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   218
    @SuppressWarnings("unused") private final int compilationLevelAdjustment;
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   219
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   220
    private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   221
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   222
    private final Iterable<HotSpotVMEventListener> vmEventListeners;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   223
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   224
    /**
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   225
     * Stores the result of {@link HotSpotJVMCICompilerFactory#getTrivialPrefixes()} so that it can
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   226
     * be read from the VM.
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   227
     */
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   228
    @SuppressWarnings("unused") private final String[] trivialPrefixes;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   229
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   230
    @SuppressWarnings("try")
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   231
    private HotSpotJVMCIRuntime() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   232
        compilerToVm = new CompilerToVM();
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   233
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   234
        try (InitTimer t = timer("HotSpotVMConfig<init>")) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   235
            config = new HotSpotVMConfig(compilerToVm);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   236
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   237
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   238
        String hostArchitecture = config.getHostArchitectureName();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   239
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   240
        HotSpotJVMCIBackendFactory factory;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   241
        try (InitTimer t = timer("find factory:", hostArchitecture)) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   242
            factory = findFactory(hostArchitecture);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   243
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   244
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   245
        try (InitTimer t = timer("create JVMCI backend:", hostArchitecture)) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   246
            hostBackend = registerBackend(factory.createJVMCIBackend(this, null));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   247
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   248
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   249
        vmEventListeners = Services.load(HotSpotVMEventListener.class);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   250
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   251
        JVMCIMetaAccessContext context = null;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   252
        for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   253
            context = vmEventListener.createMetaAccessContext(this);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   254
            if (context != null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   255
                break;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   256
            }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   257
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   258
        if (context == null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   259
            context = new HotSpotJVMCIMetaAccessContext();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   260
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   261
        metaAccessContext = context;
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   262
35570
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   263
        boolean printFlags = Option.PrintFlags.getBoolean();
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   264
        boolean showFlags = Option.ShowFlags.getBoolean();
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   265
        if (printFlags || showFlags) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   266
            Option.printFlags(System.out);
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   267
            if (printFlags) {
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   268
                System.exit(0);
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   269
            }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   270
        }
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   271
584ae5cfe100 8146820: JVMCI options should not use System.getProperty directly
twisti
parents: 35565
diff changeset
   272
        if (Option.PrintConfig.getBoolean()) {
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   273
            printConfig(config, compilerToVm);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   274
        }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   275
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   276
        compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory();
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   277
        if (compilerFactory instanceof HotSpotJVMCICompilerFactory) {
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   278
            hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory;
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   279
            trivialPrefixes = hsCompilerFactory.getTrivialPrefixes();
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   280
            compilationLevelAdjustment = hsCompilerFactory.getCompilationLevelAdjustment(config);
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   281
        } else {
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   282
            hsCompilerFactory = null;
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   283
            trivialPrefixes = null;
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   284
            compilationLevelAdjustment = 0;
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   285
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   286
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   287
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   288
    private JVMCIBackend registerBackend(JVMCIBackend backend) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   289
        Class<? extends Architecture> arch = backend.getCodeCache().getTarget().arch.getClass();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   290
        JVMCIBackend oldValue = backends.put(arch, backend);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   291
        assert oldValue == null : "cannot overwrite existing backend for architecture " + arch.getSimpleName();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   292
        return backend;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   293
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   294
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   295
    public ResolvedJavaType fromClass(Class<?> javaClass) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   296
        return metaAccessContext.fromClass(javaClass);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   297
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   298
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   299
    public HotSpotVMConfig getConfig() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   300
        return config;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   301
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   302
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   303
    public CompilerToVM getCompilerToVM() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   304
        return compilerToVm;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   305
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   306
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   307
    public JVMCIMetaAccessContext getMetaAccessContext() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   308
        return metaAccessContext;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   309
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   310
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   311
    public JVMCICompiler getCompiler() {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   312
        if (compiler == null) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   313
            synchronized (this) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   314
                if (compiler == null) {
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   315
                    compiler = compilerFactory.createCompiler(this);
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   316
                }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   317
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   318
        }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   319
        return compiler;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   320
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   321
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   322
    public JavaType lookupType(String name, HotSpotResolvedObjectType accessingType, boolean resolve) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   323
        Objects.requireNonNull(accessingType, "cannot resolve type without an accessing class");
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   324
        // If the name represents a primitive type we can short-circuit the lookup.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   325
        if (name.length() == 1) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   326
            JavaKind kind = JavaKind.fromPrimitiveOrVoidTypeChar(name.charAt(0));
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   327
            return fromClass(kind.toJavaClass());
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   328
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   329
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   330
        // Resolve non-primitive types in the VM.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   331
        HotSpotResolvedObjectTypeImpl hsAccessingType = (HotSpotResolvedObjectTypeImpl) accessingType;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   332
        final HotSpotResolvedObjectTypeImpl klass = compilerToVm.lookupType(name, hsAccessingType.mirror(), resolve);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   333
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   334
        if (klass == null) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   335
            assert resolve == false;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   336
            return HotSpotUnresolvedJavaType.create(this, name);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   337
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   338
        return klass;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   339
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   340
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   341
    public JVMCIBackend getHostJVMCIBackend() {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   342
        return hostBackend;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   343
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   344
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   345
    public <T extends Architecture> JVMCIBackend getJVMCIBackend(Class<T> arch) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   346
        assert arch != Architecture.class;
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   347
        return backends.get(arch);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   348
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   349
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   350
    public Map<Class<? extends Architecture>, JVMCIBackend> getJVMCIBackends() {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   351
        return Collections.unmodifiableMap(backends);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   352
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   353
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   354
    /**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   355
     * Called from the VM.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   356
     */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   357
    @SuppressWarnings({"unused"})
38666
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   358
    private int adjustCompilationLevel(Class<?> declaringClass, String name, String signature, boolean isOsr, int level) {
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   359
        return hsCompilerFactory.adjustCompilationLevel(config, declaringClass, name, signature, isOsr, level);
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   360
    }
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   361
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   362
    /**
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   363
     * Called from the VM.
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   364
     */
5ff19807abd5 8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents: 38663
diff changeset
   365
    @SuppressWarnings({"unused"})
35592
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35582
diff changeset
   366
    private CompilationRequestResult compileMethod(HotSpotResolvedJavaMethod method, int entryBCI, long jvmciEnv, int id) {
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35582
diff changeset
   367
        CompilationRequestResult result = getCompiler().compileMethod(new HotSpotCompilationRequest(method, entryBCI, jvmciEnv, id));
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35582
diff changeset
   368
        assert result != null : "compileMethod must always return something";
5814f874d736 8147432: JVMCI should report bailouts in PrintCompilation output
never
parents: 35582
diff changeset
   369
        return result;
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   370
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   371
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   372
    /**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   373
     * Shuts down the runtime.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   374
     *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   375
     * Called from the VM.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   376
     */
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   377
    @SuppressWarnings({"unused"})
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   378
    private void shutdown() throws Exception {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   379
        for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   380
            vmEventListener.notifyShutdown();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   381
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   382
    }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   383
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   384
    /**
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   385
     * Notify on successful install into the CodeCache.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   386
     *
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   387
     * @param hotSpotCodeCacheProvider
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   388
     * @param installedCode
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 35570
diff changeset
   389
     * @param compiledCode
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   390
     */
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 35570
diff changeset
   391
    void notifyInstall(HotSpotCodeCacheProvider hotSpotCodeCacheProvider, InstalledCode installedCode, CompiledCode compiledCode) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   392
        for (HotSpotVMEventListener vmEventListener : vmEventListeners) {
35582
c32a0cc19877 8147599: [JVMCI] simplify code installation interface
rschatz
parents: 35570
diff changeset
   393
            vmEventListener.notifyInstall(hotSpotCodeCacheProvider, installedCode, compiledCode);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   394
        }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   395
    }
33632
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   396
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   397
    private static void printConfig(HotSpotVMConfig config, CompilerToVM vm) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   398
        Field[] fields = config.getClass().getDeclaredFields();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   399
        Map<String, Field> sortedFields = new TreeMap<>();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   400
        for (Field f : fields) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   401
            if (!f.isSynthetic() && !Modifier.isStatic(f.getModifiers())) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   402
                f.setAccessible(true);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   403
                sortedFields.put(f.getName(), f);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   404
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   405
        }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   406
        for (Field f : sortedFields.values()) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   407
            try {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   408
                String line = String.format("%9s %-40s = %s%n", f.getType().getSimpleName(), f.getName(), pretty(f.get(config)));
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   409
                byte[] lineBytes = line.getBytes();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   410
                vm.writeDebugOutput(lineBytes, 0, lineBytes.length);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   411
                vm.flushDebugOutput();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   412
            } catch (Exception e) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   413
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   414
        }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   415
    }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   416
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   417
    private static String pretty(Object value) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   418
        if (value == null) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   419
            return "null";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   420
        }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   421
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   422
        Class<?> klass = value.getClass();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   423
        if (value instanceof String) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   424
            return "\"" + value + "\"";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   425
        } else if (value instanceof Method) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   426
            return "method \"" + ((Method) value).getName() + "\"";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   427
        } else if (value instanceof Class<?>) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   428
            return "class \"" + ((Class<?>) value).getSimpleName() + "\"";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   429
        } else if (value instanceof Integer) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   430
            if ((Integer) value < 10) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   431
                return value.toString();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   432
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   433
            return value + " (0x" + Integer.toHexString((Integer) value) + ")";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   434
        } else if (value instanceof Long) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   435
            if ((Long) value < 10 && (Long) value > -10) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   436
                return value + "l";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   437
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   438
            return value + "l (0x" + Long.toHexString((Long) value) + "l)";
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   439
        } else if (klass.isArray()) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   440
            StringBuilder str = new StringBuilder();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   441
            int dimensions = 0;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   442
            while (klass.isArray()) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   443
                dimensions++;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   444
                klass = klass.getComponentType();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   445
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   446
            int length = Array.getLength(value);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   447
            str.append(klass.getSimpleName()).append('[').append(length).append(']');
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   448
            for (int i = 1; i < dimensions; i++) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   449
                str.append("[]");
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   450
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   451
            str.append(" {");
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   452
            for (int i = 0; i < length; i++) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   453
                str.append(pretty(Array.get(value, i)));
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   454
                if (i < length - 1) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   455
                    str.append(", ");
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   456
                }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   457
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   458
            str.append('}');
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   459
            return str.toString();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   460
        }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   461
        return value.toString();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   462
    }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   463
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   464
    public OutputStream getLogStream() {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   465
        return new OutputStream() {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   466
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   467
            @Override
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   468
            public void write(byte[] b, int off, int len) throws IOException {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   469
                if (b == null) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   470
                    throw new NullPointerException();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   471
                } else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length || (off + len) < 0) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   472
                    throw new IndexOutOfBoundsException();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   473
                } else if (len == 0) {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   474
                    return;
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   475
                }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   476
                compilerToVm.writeDebugOutput(b, off, len);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   477
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   478
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   479
            @Override
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   480
            public void write(int b) throws IOException {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   481
                write(new byte[]{(byte) b}, 0, 1);
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   482
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   483
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   484
            @Override
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   485
            public void flush() throws IOException {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   486
                compilerToVm.flushDebugOutput();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   487
            }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   488
        };
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   489
    }
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   490
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   491
    /**
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   492
     * Collects the current values of all JVMCI benchmark counters, summed up over all threads.
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   493
     */
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   494
    public long[] collectCounters() {
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   495
        return compilerToVm.collectCounters();
038347770a9e 8139170: JVMCI refresh
twisti
parents: 33160
diff changeset
   496
    }
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
diff changeset
   497
}