-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GR-61151] Trim internal JFR stacktraces to match OpenJDK #10385
base: master
Are you sure you want to change the base?
Changes from 5 commits
9da1e01
9b3f21d
5e2568b
a8101b2
c16e3d8
2a1c556
24f3a22
aaf3ac4
c27627a
936b8fc
cab4264
5e4048d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import com.oracle.svm.core.code.CodeInfoTable; | ||
import com.oracle.svm.core.code.FrameInfoQueryResult; | ||
import com.oracle.svm.core.code.UntetheredCodeInfo; | ||
import com.oracle.svm.core.jdk.UninterruptibleUtils; | ||
import com.oracle.svm.core.jfr.JfrBuffer; | ||
import com.oracle.svm.core.jfr.JfrFrameType; | ||
import com.oracle.svm.core.jfr.JfrNativeEventWriter; | ||
|
@@ -56,6 +57,7 @@ | |
public final class SamplerJfrStackTraceSerializer implements SamplerStackTraceSerializer { | ||
/** This value is used by multiple threads but only by a single thread at a time. */ | ||
private static final CodeInfoDecoder.FrameInfoCursor FRAME_INFO_CURSOR = new CodeInfoDecoder.FrameInfoCursor(); | ||
private static final String SUBSTRATEVM_PREFIX = "com.oracle.svm"; | ||
|
||
@Override | ||
@Uninterruptible(reason = "Prevent JFR recording and epoch change.") | ||
|
@@ -167,8 +169,12 @@ private static int visitFrame(JfrNativeEventWriterData data, CodeInfo codeInfo, | |
int numStackTraceElements = 0; | ||
FRAME_INFO_CURSOR.initialize(codeInfo, ip, false); | ||
while (FRAME_INFO_CURSOR.advance()) { | ||
FrameInfoQueryResult frame = FRAME_INFO_CURSOR.get(); | ||
if (SubstrateJVM.getStackTraceRepo().getTrimInternalStackTraces() && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's constant, I prefer moving the condition before the loop, even if the compiler can do that for us ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm I'm not sure we can move the conditional out of the loop since we must recheck it with each new advancement of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I was only talking about moving |
||
UninterruptibleUtils.String.startsWith(frame.getSourceClassName(), SUBSTRATEVM_PREFIX)) { | ||
continue; | ||
} | ||
if (data.isNonNull()) { | ||
FrameInfoQueryResult frame = FRAME_INFO_CURSOR.get(); | ||
serializeStackTraceElement(data, frame); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this additional check be within the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, maybe moving it inside There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I don't think it should be moved inside the |
||
} | ||
numStackTraceElements++; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2025, 2025, 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.test.jfr; | ||
|
||
import com.oracle.svm.test.jfr.events.StackTraceEvent; | ||
import com.oracle.svm.core.jfr.SubstrateJVM; | ||
|
||
import jdk.jfr.Recording; | ||
import jdk.jfr.consumer.RecordedEvent; | ||
import jdk.jfr.consumer.RecordedFrame; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestName; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TestTrimStackTraces extends JfrRecordingTest { | ||
@Rule public TestName testName = new TestName(); | ||
|
||
@Test | ||
public void test() throws Throwable { | ||
String[] events = new String[]{StackTraceEvent.class.getName()}; | ||
SubstrateJVM.getStackTraceRepo().setTrimInternalStackTraces(true); | ||
Recording recording = startRecording(events); | ||
|
||
StackTraceEvent event = new StackTraceEvent(); | ||
event.commit(); | ||
|
||
stopRecording(recording, this::validateEvents); | ||
} | ||
|
||
private void validateEvents(List<RecordedEvent> events) { | ||
assertEquals(1, events.size()); | ||
RecordedEvent event = events.getFirst(); | ||
List<RecordedFrame> frames = event.getStackTrace().getFrames(); | ||
assertTrue(frames.size() > 0); | ||
assertFalse(frames.stream().anyMatch(e -> testName.getMethodName().equals(e.getMethod().getName()))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is a constant at runtime. Too bad that we can't declare it as final here. Not sure how important that is in practice though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's a bit unfortunate. It gets set during startup once the runtime options are parsed. We also need to change this during the JFR tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to turn the option from a
RuntimeOptionKey
into aHostedOptionKey
and make sure trimming is installed at build time? Is it really necessary for the option to be mutable at run time?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it could make sense to set this option at build time with a
HostedOptionKey
. The 2 downsides would be:HostedOptionKey
to themx native-unittest
build?Do you think it's worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RE 1: I guess you could unconditionally disable trimming in
native_unittests_task
inmx_substratevm.py
. That should do the try on the gate. When you want to runmx native-unittest
on the cmd line, you need to pass it as an additional build flag.RE 2: Agreed, normal users are probably not too interested in this. Disabling trimming only really seems useful to measure JFR overhead, something only we really care about, right?
Leaving this up to you. :)