Skip to content

Commit

Permalink
[GR-47109] Support JFR event ObjectAllocationSample.
Browse files Browse the repository at this point in the history
PullRequest: graal/16849
  • Loading branch information
christianhaeubl committed Feb 10, 2024
2 parents 680090f + d721c1b commit 6d46039
Show file tree
Hide file tree
Showing 36 changed files with 1,603 additions and 143 deletions.
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-51106) Fields that are accessed via a `VarHandle` or `MethodHandle` are no longer marked as "unsafe accessed" when the `VarHandle`/`MethodHandle` can be fully intrinsified.
* (GR-49996) Ensure explicitly set image name (e.g., via `-o imagename`) is not accidentally overwritten by `-jar jarfile` option.
* (GR-48683) Together with Red Hat, we added partial support for the JFR event `OldObjectSample`.
* (GR-47109) Together with Red Hat, we added support for JFR event throttling and the event `ObjectAllocationSample`.

## GraalVM for JDK 22 (Internal Version 24.0.0)
* (GR-48304) Red Hat added support for the JFR event ThreadAllocationStatistics.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import com.oracle.svm.core.jfr.HasJfrSupport;
import com.oracle.svm.core.jfr.JfrTicks;
import com.oracle.svm.core.jfr.SubstrateJVM;
import com.oracle.svm.core.jfr.events.ObjectAllocationInNewTLABEvent;
import com.oracle.svm.core.jfr.events.JfrAllocationEvents;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.snippets.KnownIntrinsics;
import com.oracle.svm.core.snippets.SubstrateForeignCallTarget;
Expand Down Expand Up @@ -243,7 +243,7 @@ private static Object slowPathNewInstanceWithoutAllocating(DynamicHub hub, Unsig
AlignedHeader newTlab = HeapImpl.getChunkProvider().produceAlignedChunk();
return allocateInstanceInNewTlab(hub, size, newTlab);
} finally {
ObjectAllocationInNewTLABEvent.emit(startTicks, hub, size, HeapParameters.getAlignedHeapChunkSize());
JfrAllocationEvents.emit(startTicks, hub, size, HeapParameters.getAlignedHeapChunkSize());
DeoptTester.enableDeoptTesting();
}
}
Expand Down Expand Up @@ -327,7 +327,7 @@ private static Object slowPathNewArrayLikeObject0(DynamicHub hub, int length, Un
}
return array;
} finally {
ObjectAllocationInNewTLABEvent.emit(startTicks, hub, size, tlabSize);
JfrAllocationEvents.emit(startTicks, hub, size, tlabSize);
DeoptTester.enableDeoptTesting();
}
}
Expand Down Expand Up @@ -532,7 +532,7 @@ private static Descriptor retireCurrentAllocationChunk(IsolateThread thread) {

private static void sampleSlowPathAllocation(Object obj, UnsignedWord allocatedSize, int arrayLength) {
if (HasJfrSupport.get()) {
SubstrateJVM.getJfrOldObjectProfiler().sample(obj, allocatedSize, arrayLength);
SubstrateJVM.getOldObjectProfiler().sample(obj, allocatedSize, arrayLength);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.posix;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.headers.LibMSupport;
import com.oracle.svm.core.posix.headers.PosixLibM;

@AutomaticallyRegisteredImageSingleton(LibMSupport.class)
public class PosixLibMSupport implements LibMSupport {
@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public double log(double value) {
return PosixLibM.log(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.posix.headers;

import java.util.Collections;
import java.util.List;

import org.graalvm.nativeimage.c.CContext;
import org.graalvm.nativeimage.c.function.CFunction;

import com.oracle.svm.core.jfr.HasJfrSupport;

@CContext(value = LibMDependencies.class)
public class PosixLibM {
@CFunction(transition = CFunction.Transition.NO_TRANSITION)
public static native double log(double value);
}

class LibMDependencies implements CContext.Directives {
@Override
public boolean isInConfiguration() {
return HasJfrSupport.get();
}

@Override
public List<String> getHeaderFiles() {
return Collections.singletonList("<math.h>");
}

@Override
public List<String> getLibraries() {
return Collections.singletonList("m");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.windows;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.feature.AutomaticallyRegisteredImageSingleton;
import com.oracle.svm.core.headers.LibMSupport;
import com.oracle.svm.core.windows.headers.WindowsLibC;

@AutomaticallyRegisteredImageSingleton(LibMSupport.class)
public class WindowsLibMSupport implements LibMSupport {
@Override
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public double log(double value) {
return WindowsLibC.log(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class WindowsDirectives implements CContext.Directives {
"<stdio.h>",
"<stdlib.h>",
"<string.h>",
"<io.h>"
"<io.h>",
"<math.h>"
};

@Override
Expand All @@ -55,8 +56,7 @@ public boolean isInConfiguration() {
@Override
public List<String> getHeaderFiles() {
if (Platform.includedIn(Platform.WINDOWS.class)) {
List<String> result = new ArrayList<>(Arrays.asList(windowsLibs));
return result;
return new ArrayList<>(Arrays.asList(windowsLibs));
} else {
throw VMError.shouldNotReachHere("Unsupported OS");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,7 @@ public interface WCharPointer extends PointerBase {

@CFunction(transition = CFunction.Transition.NO_TRANSITION)
public static native UnsignedWord strtoull(CCharPointer string, CCharPointerPointer endPtr, int base);

@CFunction(transition = CFunction.Transition.NO_TRANSITION)
public static native double log(double value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,9 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String ol
@Option(help = "Specifies the number of entries that diagnostic buffers have.", type = OptionType.Debug)//
public static final HostedOptionKey<Integer> DiagnosticBufferSize = new HostedOptionKey<>(30);

@Option(help = "Determines if implicit exceptions are fatal if they don't have a stack trace.", type = OptionType.Debug)//
public static final RuntimeOptionKey<Boolean> ImplicitExceptionWithoutStacktraceIsFatal = new RuntimeOptionKey<>(false);

@SuppressWarnings("unused")//
@APIOption(name = "configure-reflection-metadata")//
@Option(help = "Enable runtime instantiation of reflection objects for non-invoked methods.", type = OptionType.Expert, deprecated = true)//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.collections;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;

import com.oracle.svm.core.Uninterruptible;

public final class EnumBitmask {
private EnumBitmask() {
}

public static int computeBitmask(Enum<?>[] flags) {
int result = 0;
for (Enum<?> flag : flags) {
assert flag.ordinal() <= Integer.SIZE - 1;
result |= flagBit(flag);
}
return result;
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public static boolean hasBit(int bitmask, Enum<?> flag) {
return (bitmask & flagBit(flag)) != 0;
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
private static int flagBit(Enum<?> flag) {
assert flag.ordinal() < 32;
return 1 << flag.ordinal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package com.oracle.svm.core.headers;

import jdk.graal.compiler.api.replacements.Fold;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CCharPointerPointer;
Expand All @@ -34,6 +33,8 @@

import com.oracle.svm.core.Uninterruptible;

import jdk.graal.compiler.api.replacements.Fold;

public class LibC {
public static final int EXIT_CODE_ABORT = 99;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.headers;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.Uninterruptible;

import jdk.graal.compiler.api.replacements.Fold;

public class LibM {
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public static double log(double value) {
return libm().log(value);
}

@Fold
static LibMSupport libm() {
return ImageSingletons.lookup(LibMSupport.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. 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.headers;

import com.oracle.svm.core.Uninterruptible;

public interface LibMSupport {
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
double log(double value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ public static int abs(int a) {
public static long abs(long a) {
return (a < 0) ? -a : a;
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static long floorToLong(double value) {
assert value == value : "must not be NaN";
return (long) value;
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static long ceilToLong(double a) {
long floor = floorToLong(a);
return a > floor ? floor + 1 : floor;
}
}

public static class Byte {
Expand Down
Loading

0 comments on commit 6d46039

Please sign in to comment.