src/jdk.internal.vm.compiler.management/share/classes/org/graalvm/compiler/hotspot/jmx/GraalMBeans.java
author psandoz
Wed, 31 Jan 2018 17:43:46 -0800
changeset 48830 11920d5d14a8
parent 47557 8b2054b7d02c
permissions -rw-r--r--
8196533: Update CondyNestedTest.java to compile jcod file Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47557
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     1
/*
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     4
 *
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     8
 *
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    13
 * accompanied this code).
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    14
 *
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    18
 *
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    21
 * questions.
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    22
 */
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    23
package org.graalvm.compiler.hotspot.jmx;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    24
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    25
import java.util.ArrayList;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    26
import java.util.Collections;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    27
import java.util.List;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    28
import java.util.Map;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    29
import java.util.Set;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    30
import jdk.vm.ci.runtime.JVMCI;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    31
import jdk.vm.ci.runtime.JVMCICompiler;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    32
import jdk.vm.ci.runtime.JVMCIRuntime;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    33
import org.graalvm.compiler.hotspot.HotSpotGraalCompiler;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    34
import sun.management.spi.PlatformMBeanProvider;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    35
import sun.management.spi.PlatformMBeanProvider.PlatformComponent;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    36
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    37
public final class GraalMBeans extends PlatformMBeanProvider {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    38
    @Override
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    39
    public List<PlatformComponent<?>> getPlatformComponentList() {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    40
        List<PlatformComponent<?>> components = new ArrayList<>();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    41
        try {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    42
            Object bean = findGraalRuntimeBean();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    43
            if (bean != null) {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    44
                components.add(new HotSpotRuntimeMBeanComponent(bean));
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    45
            }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    46
        } catch (InternalError | LinkageError err) {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    47
            // go on and ignore
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    48
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    49
        return components;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    50
    }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    51
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    52
    public static Object findGraalRuntimeBean() {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    53
        JVMCIRuntime r = JVMCI.getRuntime();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    54
        JVMCICompiler c = r.getCompiler();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    55
        if (c instanceof HotSpotGraalCompiler) {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    56
            return ((HotSpotGraalCompiler) c).mbean();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    57
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    58
        return null;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    59
    }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    60
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    61
    private static final class HotSpotRuntimeMBeanComponent implements PlatformComponent<Object> {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    62
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    63
        private final String name;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    64
        private final Object mbean;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    65
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    66
        HotSpotRuntimeMBeanComponent(Object mbean) {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    67
            this.name = "org.graalvm.compiler.hotspot:type=Options";
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    68
            this.mbean = mbean;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    69
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    70
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    71
        @Override
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    72
        public Set<Class<?>> mbeanInterfaces() {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    73
            return Collections.emptySet();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    74
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    75
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    76
        @Override
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    77
        public Set<String> mbeanInterfaceNames() {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    78
            return Collections.emptySet();
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    79
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    80
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    81
        @Override
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    82
        public String getObjectNamePattern() {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    83
            return name;
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    84
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    85
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    86
        @Override
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    87
        public Map<String, Object> nameToMBeanMap() {
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    88
            return Collections.<String, Object>singletonMap(name, mbean);
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    89
        }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    90
    }
8b2054b7d02c 8182701: Modify JVMCI to allow Graal Compiler to expose platform MBean
jtulach
parents:
diff changeset
    91
}