src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalJVMCIServiceLocator.java
author dlong
Tue, 24 Sep 2019 12:47:15 -0400
changeset 58299 6df94ce3ab2f
parent 54084 84f10bbf993f
permissions -rw-r--r--
8229201: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 54084
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     4
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     8
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    13
 * accompanied this code).
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    14
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    18
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    21
 * questions.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 47216
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 47216
diff changeset
    24
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    25
package org.graalvm.compiler.hotspot;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    26
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    27
import org.graalvm.compiler.serviceprovider.ServiceProvider;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    28
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    29
import jdk.vm.ci.common.NativeImageReinitialize;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    30
import jdk.vm.ci.hotspot.HotSpotVMEventListener;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    31
import jdk.vm.ci.runtime.JVMCICompilerFactory;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    32
import jdk.vm.ci.services.JVMCIServiceLocator;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    33
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    34
@ServiceProvider(JVMCIServiceLocator.class)
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    35
public final class HotSpotGraalJVMCIServiceLocator extends JVMCIServiceLocator {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    36
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    37
    /**
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    38
     * Holds the state shared between all {@link HotSpotGraalJVMCIServiceLocator} instances. This is
46459
7d4e637d3f21 8180267: Update Graal
kvn
parents: 46458
diff changeset
    39
     * necessary as a service provider instance is created each time the service is loaded.
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    40
     */
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    41
    private static final class Shared {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    42
        static final Shared SINGLETON = new Shared();
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    43
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    44
        <T> T getProvider(Class<T> service, HotSpotGraalJVMCIServiceLocator locator) {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    45
            if (service == JVMCICompilerFactory.class) {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    46
                return service.cast(new HotSpotGraalCompilerFactory(locator));
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    47
            } else if (service == HotSpotVMEventListener.class) {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    48
                if (graalRuntime != null) {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    49
                    return service.cast(new HotSpotGraalVMEventListener(graalRuntime));
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    50
                }
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    51
            }
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    52
            return null;
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    53
        }
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    54
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    55
        @NativeImageReinitialize private HotSpotGraalRuntime graalRuntime;
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    56
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    57
        /**
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    58
         * Notifies this object of the compiler created via {@link HotSpotGraalJVMCIServiceLocator}.
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    59
         */
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    60
        void onCompilerCreation(HotSpotGraalCompiler compiler) {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    61
            assert this.graalRuntime == null : "only expect a single JVMCICompiler to be created";
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    62
            this.graalRuntime = (HotSpotGraalRuntime) compiler.getGraalRuntime();
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    63
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    64
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    65
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    66
    @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    67
    public <T> T getProvider(Class<T> service) {
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    68
        return Shared.SINGLETON.getProvider(service, this);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    69
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    70
44836
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    71
    /**
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    72
     * Notifies this object of the compiler created via {@link HotSpotGraalJVMCIServiceLocator}.
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    73
     */
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    74
    @SuppressWarnings("static-method")
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    75
    void onCompilerCreation(HotSpotGraalCompiler compiler) {
45196b7066e3 8177845: Need a mechanism to load Graal
dnsimon
parents: 43972
diff changeset
    76
        Shared.SINGLETON.onCompilerCreation(compiler);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    77
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    78
}