Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/mx.sdk/mx_sdk_vm_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ def contents(self):
if isinstance(image_config, mx_sdk.LauncherConfig) or (isinstance(image_config, mx_sdk.LanguageLibraryConfig) and image_config.launchers):
build_args += [
'--install-exit-handlers',
'--enable-monitoring',
'--enable-monitoring=jvmstat,heapdump,jfr',
'-H:+DumpRuntimeCompilationOnSignal',
]

Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-41674) Class instanceOf and isAssignableFrom checks do need to make the checked type reachable.
* (GR-41100) Add support for `-XX:HeapDumpPath` to control where heap dumps are created.
* (GR-42148) Adjust build output to report types (primitives, classes, interfaces, and arrays) instead of classes and revise the output schema of `-H:BuildOutputJSONFile`.
* (GR-40463) Red Hat added initial support for JMX, which can be enabled with the `--enable-monitoring` option (e.g. `--enable-monitoring=jmxclient,jmxserver`).

## Version 22.3.0
* (GR-35721) Remove old build output style and the `-H:±BuildOutputUseNewStyle` option.
Expand Down
12 changes: 12 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
"jdk.internal.perf",
"jdk.internal.ref",
"jdk.internal.reflect",
"jdk.internal.vm",
"jdk.internal.util",
],
"java.desktop": [
Expand All @@ -275,6 +276,12 @@
"jdk.management": [
"com.sun.management.internal"
],
"jdk.management.agent": [
"jdk.internal.agent",
],
"jdk.management.jfr": [
"jdk.management.jfr"
],
"jdk.httpserver@19+": [
"sun.net.httpserver.simpleserver",
],
Expand Down Expand Up @@ -797,6 +804,9 @@
"requires": [
"java.compiler",
"jdk.jfr",
"java.management",
"jdk.management.jfr",
"java.rmi",
],
"requiresConcealed" : {
"java.base" : [
Expand Down Expand Up @@ -1262,6 +1272,8 @@
"java.net.http",
"jdk.sctp",
"[email protected]",
"jdk.management.agent",
"jdk.management.jfr",
],
"uses" : [
"org.graalvm.nativeimage.Platform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public final class GCImpl implements GC {
private UnsignedWord sizeBefore = WordFactory.zero();
private boolean collectionInProgress = false;
private UnsignedWord collectionEpoch = WordFactory.zero();
private long lastWholeHeapExaminedTimeNs = -1;

@Platforms(Platform.HOSTED_ONLY.class)
GCImpl() {
Expand Down Expand Up @@ -287,6 +288,9 @@ private boolean doCollectOnce(GCCause cause, long requestingNanoTime, boolean co
}
scavenge(!complete);
verifyAfterGC();
if (complete) {
lastWholeHeapExaminedTimeNs = System.nanoTime();
}
} finally {
collectionTimer.close();
}
Expand Down Expand Up @@ -1179,6 +1183,17 @@ public UnsignedWord getCollectionEpoch() {
return collectionEpoch;
}

/**
* Returns the time in ns that the last full GC happened relative to when the program was
* started. If no full GC has yet been run, it returns the time since the first allocation.
*/
public long getLastWholeHeapExaminedTimeNs() {
if (lastWholeHeapExaminedTimeNs < 0) {
return HeapImpl.getChunkProvider().getFirstAllocationTime();
}
return lastWholeHeapExaminedTimeNs;
}

public GCAccounting getAccounting() {
return accounting;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ public void dirtyAllReferencesOf(Object obj) {
}
}

@Override
public long getMaxObjectInspectionAge() {
return (System.nanoTime() - getGCImpl().getLastWholeHeapExaminedTimeNs()) / 1000000;
}

static Pointer getImageHeapStart() {
int imageHeapOffsetInAddressSpace = Heap.getHeap().getImageHeapOffsetInAddressSpace();
if (imageHeapOffsetInAddressSpace > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public final class VMInspectionOptions {
private static final String MONITORING_HEAPDUMP_NAME = "heapdump";
private static final String MONITORING_JFR_NAME = "jfr";
private static final String MONITORING_JVMSTAT_NAME = "jvmstat";
private static final String MONITORING_ALLOWED_VALUES = "'" + MONITORING_HEAPDUMP_NAME + "', '" + MONITORING_JFR_NAME + "', '" + MONITORING_JVMSTAT_NAME + "', or '" + MONITORING_ALL_NAME +
"' (defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";
private static final String MONITORING_JMXCLIENT_NAME = "jmxclient";
private static final String MONITORING_JMXSERVER_NAME = "jmxserver";
private static final String MONITORING_ALLOWED_VALUES = "'" + MONITORING_HEAPDUMP_NAME + "', '" + MONITORING_JFR_NAME + "', '" + MONITORING_JVMSTAT_NAME + "', '" + MONITORING_JMXSERVER_NAME +
"', '" + MONITORING_JMXCLIENT_NAME + "', or '" + MONITORING_ALL_NAME + "' (defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";

@APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_ALL_NAME) //
@Option(help = "Enable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain " + MONITORING_ALLOWED_VALUES + ". " +
Expand All @@ -59,7 +61,7 @@ public final class VMInspectionOptions {

public static void validateEnableMonitoringFeatures(OptionKey<?> optionKey) {
Set<String> enabledFeatures = getEnabledMonitoringFeatures();
enabledFeatures.removeAll(List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME, MONITORING_JVMSTAT_NAME, MONITORING_ALL_NAME));
enabledFeatures.removeAll(List.of(MONITORING_HEAPDUMP_NAME, MONITORING_JFR_NAME, MONITORING_JVMSTAT_NAME, MONITORING_JMXCLIENT_NAME, MONITORING_JMXSERVER_NAME, MONITORING_ALL_NAME));
if (!enabledFeatures.isEmpty()) {
throw UserError.abort("The option %s contains invalid value(s): %s. It can only contain %s.", optionKey.getName(), String.join(", ", enabledFeatures), MONITORING_ALLOWED_VALUES);
}
Expand Down Expand Up @@ -94,6 +96,16 @@ public static boolean hasJvmstatSupport() {
return hasAllOrKeywordMonitoringSupport(MONITORING_JVMSTAT_NAME) && !Platform.includedIn(WINDOWS.class);
}

@Fold
public static boolean hasJmxServerSupport() {
return hasAllOrKeywordMonitoringSupport(MONITORING_JMXSERVER_NAME) && !Platform.includedIn(WINDOWS.class);
}

@Fold
public static boolean hasJmxClientSupport() {
return hasAllOrKeywordMonitoringSupport(MONITORING_JMXCLIENT_NAME) && !Platform.includedIn(WINDOWS.class);
}

@Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User) //
public static final HostedOptionKey<Boolean> DumpRuntimeCompilationOnSignal = new HostedOptionKey<>(false, VMInspectionOptions::validateOnSignalOption);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,7 @@ public List<Class<?>> getLoadedClasses() {
/** Consider all references in the given object as needing remembered set entries. */
@Uninterruptible(reason = "Ensure that no GC can occur between modification of the object and this call.", callerMustBe = true)
public abstract void dirtyAllReferencesOf(Object obj);

/** Returns time since the last full GC in milliseconds. */
public abstract long getMaxObjectInspectionAge();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.core.jdk.management;

import java.util.function.BooleanSupplier;
import com.oracle.svm.core.VMInspectionOptions;

public class JmxClientNotIncluded implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
return !VMInspectionOptions.hasJmxClientSupport();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.core.jdk.management;

import java.util.function.BooleanSupplier;

import com.oracle.svm.core.VMInspectionOptions;

public class JmxIncluded implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
return VMInspectionOptions.hasJmxServerSupport() || VMInspectionOptions.hasJmxClientSupport();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.core.jdk.management;

import java.util.function.BooleanSupplier;

import com.oracle.svm.core.VMInspectionOptions;

public class JmxServerIncluded implements BooleanSupplier {
@Override
public boolean getAsBoolean() {
return VMInspectionOptions.hasJmxServerSupport();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2022, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.oracle.svm.core.jdk.management;

import com.oracle.svm.core.util.VMError;

public class ManagementAgentStartupHook implements com.oracle.svm.core.jdk.RuntimeSupport.Hook {

@Override
public void execute(boolean isFirstIsolate) {
try {
jdk.internal.agent.Agent.startAgent();
} catch (Exception e) {
throw VMError.shouldNotReachHere("ManagementFeature start-up hook failed: " + e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import com.oracle.svm.core.thread.ThreadListenerSupportFeature;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.util.ReflectionUtil;
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.VMInspectionOptions;

/** See {@link ManagementSupport} for documentation. */
@AutomaticallyRegisteredFeature
Expand Down Expand Up @@ -90,6 +92,20 @@ public void duringSetup(DuringSetupAccess access) {
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$IdentityMapping");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.DescriptorCache");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.remote.util.ClassLogger");
// Adding FlightRecorderMXBean in ManagementSupport class results in requiring the below
// policies. The policies are normally specified as part of JmxCommonFeature,
// but if JmxServer and JmxClient are not included in the image build,
// then we have to provide the policies here.
if (HasJfrSupport.get() && !VMInspectionOptions.hasJmxServerSupport() && !VMInspectionOptions.hasJmxClientSupport()) {
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.remote.util.EnvHelp");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.Introspector");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.MXBeanIntrospector");
RuntimeClassInitialization.initializeAtBuildTime("java.beans.Introspector");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.JavaBeansAccessor");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.StandardMBeanIntrospector");
RuntimeClassInitialization.initializeAtBuildTime("jdk.management.jfr.MBeanUtils");
}

}

/**
Expand Down
Loading