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

8282172: CompileBroker::log_metaspace_failure is called from non-Java/compiler threads #7555

Closed

Conversation

shipilev
Copy link
Member

@shipilev shipilev commented Feb 21, 2022

In several places in hotspot, we call CompileBroker::log_metaspace_failure(). I believe the intent is to call it from compiler threads only, because it ends up calling:

  void log_metaspace_failure(const char* reason) {
    ResourceMark rm;
    StringLogMessage lm;
    lm.print("%4d COMPILE PROFILING SKIPPED: %s", -1, reason);
    lm.print("\n");
    log(JavaThread::current(), "%s", (const char*)lm);
  }

...which would fail the cast in JavaThread::current() if current thread is not Java thread (compiler threads are Java threads too).

It clearly manifests on JDK-8282170 test:

12700 breakpoints set
12800 breakpoints set
12900 breakpoints set
13000 breakpoints set
# To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc: SuppressErrorAt=/thread.hpp:1458
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (/home/shade/trunks/jdk/src/hotspot/share/runtime/thread.hpp:1458), pid=889379, tid=889389
# assert(t->is_Java_thread()) failed: incorrect cast to JavaThread
V [libjvm.so+0xacfad4] CompilationLog::log_metaspace_failure(char const*)+0x494
V [libjvm.so+0xac84b0] CompileBroker::log_metaspace_failure()+0x20
V [libjvm.so+0x15069e9] Method::build_method_counters(Thread*, Method*)+0x119
V [libjvm.so+0x150851b] BreakpointInfo::set(Method*)+0xfb
V [libjvm.so+0x127d5ea] JvmtiBreakpoint::each_method_version_do(void (Method::*)(int))+0x5a
V [libjvm.so+0x1b342ae] VM_Operation::evaluate()+0x18e 

Additional testing:

  • Linux x86_64 fastdebug does not fail JDK-8282170 test anymore

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8282172: CompileBroker::log_metaspace_failure is called from non-Java/compiler threads

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7555/head:pull/7555
$ git checkout pull/7555

Update a local copy of the PR:
$ git checkout pull/7555
$ git pull https://git.openjdk.java.net/jdk pull/7555/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7555

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7555.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 21, 2022

👋 Welcome back shade! 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 Feb 21, 2022
@openjdk
Copy link

openjdk bot commented Feb 21, 2022

@shipilev The following label will be automatically applied to this pull request:

  • hotspot-compiler

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

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Feb 21, 2022
@mlbridge
Copy link

mlbridge bot commented Feb 21, 2022

Webrevs

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

No, it could be called from Java execution thread too when profiling is triggered. But yes it was assumed that only Java thread can ask for creation MethodData.
On other hand log() methods accepts Thread* parameter and just record it:
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/utilities/events.hpp#L183
May be we don't need to cast it to JavaThread in this case.

@shipilev
Copy link
Member Author

shipilev commented Feb 23, 2022

No, it could be called from Java execution thread too when profiling is triggered. But yes it was assumed that only Java thread can ask for creation MethodData. On other hand log() methods accepts Thread* parameter and just record it: https://github.com/openjdk/jdk/blob/master/src/hotspot/share/utilities/events.hpp#L183 May be we don't need to cast it to JavaThread in this case.

Yes, this would also work:

diff --git a/src/hotspot/share/compiler/compileBroker.cpp b/src/hotspot/share/compiler/compileBroker.cpp
index 1c8656044b5..62c45e6adca 100644
--- a/src/hotspot/share/compiler/compileBroker.cpp
+++ b/src/hotspot/share/compiler/compileBroker.cpp
@@ -227,11 +227,11 @@ class CompilationLog : public StringEventLog {
   void log_metaspace_failure(const char* reason) {
     ResourceMark rm;
     StringLogMessage lm;
     lm.print("%4d   COMPILE PROFILING SKIPPED: %s", -1, reason);
     lm.print("\n");
-    log(JavaThread::current(), "%s", (const char*)lm);
+    log(Thread::current(), "%s", (const char*)lm);
   }
 };
 
 static CompilationLog* _compilation_log = NULL;

...but it is odd to: a) have the rest of CompilationLog accept JavaThread only; b) having COMPILE SKIPPED printed when we are not dealing with any compiler/Java thread, for example from VMThread / JVMTI code like on the path in the PR body.

void CompileBroker::log_metaspace_failure() {
  const char* message = "some methods may not be compiled because metaspace "
                        "is out of memory";
  if (_compilation_log != NULL) {
    _compilation_log->log_metaspace_failure(message);
  }
  if (PrintCompilation) {
    tty->print_cr("COMPILE PROFILING SKIPPED: %s", message); // <--- from here
  }
}

So I still believe filtering non-Java/compiler threads at CompileBroker::log_metaspace_failure() is the proper fix.

@shipilev shipilev changed the title 8282172: CompileBroker::log_metaspace_failure is called from non-compiler threads 8282172: CompileBroker::log_metaspace_failure is called from non-Java/compiler threads Feb 23, 2022
Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good.

@openjdk
Copy link

openjdk bot commented Feb 23, 2022

@shipilev 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:

8282172: CompileBroker::log_metaspace_failure is called from non-Java/compiler threads

Reviewed-by: kvn, thartmann

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 45 new commits pushed to the master branch:

  • cd36be4: 8206187: javax/management/remote/mandatory/connection/DefaultAgentFilterTest.java fails with Port already in use
  • bf19fc6: 8280357: user.home = "?" when running with systemd DynamicUser=true
  • b6843a1: 8005885: enhance PrintCodeCache to print more data
  • 23995f8: 8281525: Enable Zc:strictStrings flag in Visual Studio build
  • 20e78f7: 8282307: Parallel: Incorrect discovery mode in PCReferenceProcessor
  • 0b6862e: 8282348: Remove unused CardTable::dirty_card_iterate
  • 6fab8a2: 8277204: Implement PAC-RET branch protection on Linux/AArch64
  • abc0ce1: 8282316: Operation before String case conversion
  • 0796620: 8281944: JavaDoc throws java.lang.IllegalStateException: ERRONEOUS
  • 231e48f: 8282200: ShouldNotReachHere() reached by AsyncGetCallTrace after JDK-8280422
  • ... and 35 more: https://git.openjdk.java.net/jdk/compare/e0b49629e95c98aabe8b75ec2f7528e7fb6dcffc...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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 23, 2022
Copy link
Member

@TobiHartmann TobiHartmann 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 too.

@tstuefe
Copy link
Member

tstuefe commented Feb 25, 2022

AFAICS FormatStringEventLog::log() - which is only used from the compiler btw - is always called with the current thread. Maybe it should just use Thread::current instead?

@shipilev
Copy link
Member Author

AFAICS FormatStringEventLog::log() - which is only used from the compiler btw - is always called with the current thread. Maybe it should just use Thread::current instead?

Maybe. Let's do that separately?

@tstuefe
Copy link
Member

tstuefe commented Feb 28, 2022

AFAICS FormatStringEventLog::log() - which is only used from the compiler btw - is always called with the current thread. Maybe it should just use Thread::current instead?

Maybe. Let's do that separately?

Oh, sure.

@shipilev
Copy link
Member Author

Good. Thanks for reviews!

/integrate

@openjdk
Copy link

openjdk bot commented Feb 28, 2022

Going to push as commit 4e7fb41.
Since your change was applied there have been 61 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 28, 2022
@openjdk openjdk bot closed this Feb 28, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 28, 2022
@openjdk
Copy link

openjdk bot commented Feb 28, 2022

@shipilev Pushed as commit 4e7fb41.

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

@shipilev shipilev deleted the JDK-8282172-compiler-broker-message branch March 7, 2022 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants