diff --git a/src/hotspot/share/compiler/compilationFailureInfo.cpp b/src/hotspot/share/compiler/compilationFailureInfo.cpp index e3f3353589e..fb94102ef16 100644 --- a/src/hotspot/share/compiler/compilationFailureInfo.cpp +++ b/src/hotspot/share/compiler/compilationFailureInfo.cpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2023, Red Hat, Inc. and/or its affiliates. + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, Red Hat, Inc. and/or its affiliates. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,11 +42,16 @@ #include "utilities/ostream.hpp" #include "utilities/nativeCallStack.hpp" +int CompilationFailureInfo::current_compile_id_or_0() { + ciEnv* env = ciEnv::current(); + return (env != nullptr) ? env->compile_id() : 0; +} + CompilationFailureInfo::CompilationFailureInfo(const char* failure_reason) : _stack(2), _failure_reason(os::strdup(failure_reason)), _elapsed_seconds(os::elapsedTime()), - _compile_id(ciEnv::current()->task()->compile_id()) + _compile_id(current_compile_id_or_0()) {} CompilationFailureInfo::~CompilationFailureInfo() { diff --git a/src/hotspot/share/compiler/compilationFailureInfo.hpp b/src/hotspot/share/compiler/compilationFailureInfo.hpp index 3de62eb69da..470865a2f66 100644 --- a/src/hotspot/share/compiler/compilationFailureInfo.hpp +++ b/src/hotspot/share/compiler/compilationFailureInfo.hpp @@ -1,6 +1,6 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2023, Red Hat, Inc. and/or its affiliates. + * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, Red Hat, Inc. and/or its affiliates. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -40,6 +40,7 @@ class CompilationFailureInfo : public CHeapObj { char* const _failure_reason; const double _elapsed_seconds; const int _compile_id; + static int current_compile_id_or_0(); public: CompilationFailureInfo(const char* failure_reason); ~CompilationFailureInfo(); diff --git a/test/hotspot/jtreg/compiler/startup/StartupOutput.java b/test/hotspot/jtreg/compiler/startup/StartupOutput.java index d97bcd0019a..f74a03b226f 100644 --- a/test/hotspot/jtreg/compiler/startup/StartupOutput.java +++ b/test/hotspot/jtreg/compiler/startup/StartupOutput.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -55,5 +55,14 @@ public class StartupOutput { if (exitCode != 1 && exitCode != 0) { throw new Exception("VM crashed with exit code " + exitCode); } + + pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:InitialCodeCacheSize=1024K", "-XX:ReservedCodeCacheSize=1200k", "-version"); + out = new OutputAnalyzer(pb.start()); + // The VM should not crash but will probably fail with a "CodeCache is full. Compiler has been disabled." message + out.stdoutShouldNotContain("# A fatal error"); + exitCode = out.getExitValue(); + if (exitCode != 1 && exitCode != 0) { + throw new Exception("VM crashed with exit code " + exitCode); + } } }