Skip to content
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

8310978: JFR events SocketReadEvent/SocketWriteEvent for Socket adaptor ops #16251

Closed
wants to merge 8 commits into from

Conversation

tprinzing
Copy link
Contributor

@tprinzing tprinzing commented Oct 18, 2023

Added jfr event support to socket adapters.

Added the test jdk/jfr/event/io/TestSocketAdapterEvents.java


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8310978: JFR events SocketReadEvent/SocketWriteEvent for Socket adaptor ops (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16251/head:pull/16251
$ git checkout pull/16251

Update a local copy of the PR:
$ git checkout pull/16251
$ git pull https://git.openjdk.org/jdk.git pull/16251/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16251

View PR using the GUI difftool:
$ git pr show -t 16251

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16251.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 18, 2023

👋 Welcome back tprinzing! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 18, 2023
@openjdk
Copy link

openjdk bot commented Oct 18, 2023

@tprinzing The following labels will be automatically applied to this pull request:

  • hotspot-jfr
  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added nio nio-dev@openjdk.org hotspot-jfr hotspot-jfr-dev@openjdk.org labels Oct 18, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 18, 2023

Webrevs

@AlanBateman
Copy link
Contributor

I don't think we should be changing SocketChannelImpl here. Can you look at sun.nio.SocketInputStream and sun.nio.SocketOutputStream - these are the input/output streams for the socket adapter.

@tprinzing
Copy link
Contributor Author

okay, thanks.

bring back event offer semantics where it was fine.
}
long start = SocketReadEvent.timestamp();
int n = implRead(b, off, len);
SocketReadEvent.offer(start, n, sc.remoteAddress(), timeoutSupplier.getAsInt());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things left over from the original refactoring was to dig into why the event needs the timeout, it would be nice if that could go away.

For now, I'd prefer if the timeout could be captured once as otherwise there is no guarantee that the event will be reported with the same timeout used for the socket read. In other words, add a timeout parameter to implRead so that the method calls implRead with the timeout, avoids calling timeoutSuppler::getAsInt twice.

Copy link
Member

@egahlin egahlin Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SocketReadEvent.emit(...) has several advantages:

  • No need execute remoteAddress() when the threshold don't exceed 20 ms
  • Avoid the synchronized block in SocketChannelImpl::remoteAddress().
  • The end time is taken more close to start time.
  • One less frame for JFR to walk

The disadvantage is some code repetition, but it's not that much.

The reason static methods are used in the first place is to avoid the cost of an allocation in case the JIT fails to scalarize. It's a special case and most events should not need it. If we create other abstractions around the static methods, with a higher cost than an allocation, it defeats its purpose.

Long term, events based on value objects may be a better approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If remoteAddress is an issue then we can look at that, it may be a candidate to a @Stable field. That is probably beyond the scope of this PR of course.


public void test() throws Throwable {
try (Recording recording = new Recording()) {
try (ServerSocketChannel ss = ServerSocketChannel.open()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to name a ServerSocketChannel "ss", other tests use "ssc".

recording.start();

ss.socket().setReuseAddress(true);
ss.socket().bind(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests usually bind to the loopback address to reduce interference from other programs in the environment. Also ServerSocketChannel defines the bind method so you can do this:

InetAddress lb = InetAddress.getLoopbackAddress();
ssc.bind(new InetSocketAddress(lb, 0));

});
readerThread.start();

try (SocketChannel sc = SocketChannel.open(ss.socket().getLocalSocketAddress()); Socket s = sc.socket(); OutputStream os = s.getOutputStream()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put a line break after each ; then it would be easier to read. Also you can use ssc.getLocalAddress().

- use loopback address
- fetch timeout once
- formatting improvements
Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I like the use of offer to reduce the boiler-plate code, when acquiring the event parameters doesn't cause any allocation and just return some field value.

@openjdk
Copy link

openjdk bot commented Oct 26, 2023

@tprinzing This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8310978: JFR events SocketReadEvent/SocketWriteEvent for Socket adaptor ops

Reviewed-by: dfuchs, alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 159 new commits pushed to the master branch:

  • 1ec0d02: 8318225: RISC-V: C2 UModI
  • 96bec35: 8316996: Catalog API Enhancement: add a factory method
  • d226014: 8318850: Duplicate code in the LCMSImageLayout
  • c593f8b: 8318091: Remove empty initIDs functions
  • 4f9f195: 8318753: hsdis binutils may place libs in lib64
  • 2915d74: 8318837: javac generates wrong ldc instruction for dynamic constant loads
  • ddd0716: 8317661: [REDO] store/load order not preserved when handling memory pool due to weakly ordered memory architecture of aarch64
  • 141dae8: 8318811: Compiler directives parser swallows a character after line comments
  • 667cca9: 8288899: java/util/concurrent/ExecutorService/CloseTest.java failed with "InterruptedException: sleep interrupted"
  • b9dcd4b: 8318964: Fix build failures caused by 8315097
  • ... and 149 more: https://git.openjdk.org/jdk/compare/9843c97695fab3fec1e319027b14974d0e84bf0a...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch, @AlanBateman) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 26, 2023
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022,2023 Oracle and/or its affiliates. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Oracle copyright header checker will ask you to put a space after the comma.

if (SocketReadEvent.shouldCommit(duration)) {
SocketReadEvent.emit(start, duration, nbytes, remoteAddress(), 0);
}
SocketReadEvent.offer(start, nbytes, remoteAddress(), 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on shouldCommit+emit vs. offer, both are readable at the use sites. If we go with what you have then we'll need to look into making remoteAddress a stable field.

long start = SocketReadEvent.timestamp();
int n = implRead(b, off, len, timeout);
SocketReadEvent.offer(start, n, sc.remoteAddress(), timeout);
return n;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better, it means that the event is guaranteed to use the same timeout as the read operation.

recording.enable(IOEvent.EVENT_SOCKET_WRITE).withThreshold(Duration.ofMillis(0));
recording.start();

ssc.socket().setReuseAddress(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for setReuseAddress here.

addExpectedEvent(IOEvent.createSocketReadEvent(1, s));

int bytesRead = is.read(bs, 0, 3);
assertEquals(bytesRead, 3, "Wrong bytesRead partial buffer");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably okay although in theory the read method may return 1 or 2 bytes here. Initially I thought you should be using readNBytes here but that may involve more than one read and thus disrupt the number of events expected.

import jdk.test.lib.thread.XRun;

/**
* @test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to have the @bug tag to link to JDK-8310978.

- propagate TestSocketAdaptorEvents changes to TestSocketEvents and
  TestSocketChannelEvents.
- copyright fixups
- additional test tags
@tprinzing
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 28, 2023
@openjdk
Copy link

openjdk bot commented Oct 28, 2023

@tprinzing
Your change (at version 4b0daa5) is now ready to be sponsored by a Committer.

@AlanBateman
Copy link
Contributor

/integrate

I can sponsor but your branch is more than 2 weeks behind main line so I will need to test it in the CI first.

@AlanBateman
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 30, 2023

Going to push as commit 1183b22.
Since your change was applied there have been 162 commits pushed to the master branch:

  • 988e1df: 8318953: RISC-V: Small refactoring for MacroAssembler::test_bit
  • ce0ca47: 8319067: ProblemList serviceability/AsyncGetCallTrace/MyPackage/ASGCTBaseTest.java on linux-aarch64 in Xcomp mode
  • db34025: 8318827: RISC-V: Improve readability of fclass result testing
  • 1ec0d02: 8318225: RISC-V: C2 UModI
  • 96bec35: 8316996: Catalog API Enhancement: add a factory method
  • d226014: 8318850: Duplicate code in the LCMSImageLayout
  • c593f8b: 8318091: Remove empty initIDs functions
  • 4f9f195: 8318753: hsdis binutils may place libs in lib64
  • 2915d74: 8318837: javac generates wrong ldc instruction for dynamic constant loads
  • ddd0716: 8317661: [REDO] store/load order not preserved when handling memory pool due to weakly ordered memory architecture of aarch64
  • ... and 152 more: https://git.openjdk.org/jdk/compare/9843c97695fab3fec1e319027b14974d0e84bf0a...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 30, 2023
@openjdk openjdk bot closed this Oct 30, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Oct 30, 2023
@openjdk
Copy link

openjdk bot commented Oct 30, 2023

@AlanBateman @tprinzing Pushed as commit 1183b22.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-jfr hotspot-jfr-dev@openjdk.org integrated Pull request has been integrated nio nio-dev@openjdk.org
4 participants