Skip to content

Commit

Permalink
Merge branch 'openjdk:master' into JDK-8279560
Browse files Browse the repository at this point in the history
  • Loading branch information
dchuyko committed Mar 4, 2022
2 parents 5bc5c87 + 2c480b2 commit 02eb28a
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/compiler/compileBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,8 @@ void CompileBroker::compiler_thread_loop() {
method->clear_queued_for_compilation();
task->set_failure_reason("compilation is disabled");
}
} else {
task->set_failure_reason("breakpoints are present");
}

if (UseDynamicNumberOfCompilerThreads) {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/oops/method.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
Expand Down Expand Up @@ -1186,7 +1186,7 @@ void Method::unlink_method() {
void Method::link_method(const methodHandle& h_method, TRAPS) {
// If the code cache is full, we may reenter this function for the
// leftover methods that weren't linked.
if (_i2i_entry != NULL) {
if (adapter() != NULL) {
return;
}
assert( _code == NULL, "nothing compiled yet" );
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/opto/loopTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3370,6 +3370,11 @@ bool IdealLoopTree::do_one_iteration_loop(PhaseIdealLoop *phase) {
//=============================================================================
//------------------------------iteration_split_impl---------------------------
bool IdealLoopTree::iteration_split_impl(PhaseIdealLoop *phase, Node_List &old_new) {
if (!_head->is_Loop()) {
// Head could be a region with a NeverBranch that was added in beautify loops but the region was not
// yet transformed into a LoopNode. Bail out and wait until beautify loops turns it into a Loop node.
return false;
}
// Compute loop trip count if possible.
compute_trip_count(phase);

Expand Down
57 changes: 49 additions & 8 deletions test/hotspot/jtreg/compiler/codecache/OverflowCodeCacheTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, 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
Expand All @@ -23,7 +23,7 @@

/*
* @test OverflowCodeCacheTest
* @bug 8059550
* @bug 8059550 8279356
* @summary testing of code cache segments overflow
* @library /test/lib
* @modules java.base/jdk.internal.misc
Expand All @@ -33,11 +33,14 @@
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
* -XX:-SegmentedCodeCache
* compiler.codecache.OverflowCodeCacheTest
* -XX:-SegmentedCodeCache -Xmixed
* compiler.codecache.OverflowCodeCacheTest CompilationDisabled
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:CompileCommand=compileonly,null::*
* -XX:+SegmentedCodeCache
* -XX:+SegmentedCodeCache -Xmixed
* compiler.codecache.OverflowCodeCacheTest CompilationDisabled
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
* -XX:+WhiteBoxAPI -XX:-SegmentedCodeCache -Xmixed
* compiler.codecache.OverflowCodeCacheTest
*/

Expand All @@ -49,13 +52,21 @@
import sun.hotspot.code.CodeBlob;

import java.lang.management.MemoryPoolMXBean;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.EnumSet;

class Helper {
// Uncommon signature to prevent sharing and force creation of a new adapter
public void method(float a, float b, float c, Object o) { }
}

public class OverflowCodeCacheTest {
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
private static boolean COMPILATION_DISABLED = false;

public static void main(String[] args) {
COMPILATION_DISABLED = args.length > 0;
EnumSet<BlobType> blobTypes = BlobType.getAvailable();
for (BlobType type : blobTypes) {
new OverflowCodeCacheTest(type).test();
Expand All @@ -74,6 +85,8 @@ private void test() {
System.out.println("allocating till possible...");
ArrayList<Long> blobs = new ArrayList<>();
int compilationActivityMode = -1;
// Lock compilation to be able to better control code cache space
WHITE_BOX.lockCompilation();
try {
long addr;
int size = (int) (getHeapSize() >> 7);
Expand All @@ -88,15 +101,43 @@ private void test() {
}
}
/* now, remember compilationActivityMode to check it later, after freeing, since we
possibly have no free cache for futher work */
possibly have no free cache for further work */
compilationActivityMode = WHITE_BOX.getCompilationActivityMode();

// Use smallest allocation size to make sure all of the available space
// is filled up. Don't free these below to put some pressure on the sweeper.
while ((addr = WHITE_BOX.allocateCodeBlob(1, type.id)) != 0) { }
} finally {
try {
// Trigger creation of a new adapter for Helper::method
// which will fail because we are out of code cache space.
Helper helper = new Helper();
} catch (VirtualMachineError e) {
// Expected
}
// Free code cache space
for (Long blob : blobs) {
WHITE_BOX.freeCodeBlob(blob);
}

// Convert some nmethods to zombie and then free them to re-enable compilation
WHITE_BOX.unlockCompilation();
WHITE_BOX.forceNMethodSweep();
WHITE_BOX.forceNMethodSweep();

// Trigger compilation of Helper::method which will hit an assert because
// adapter creation failed above due to a lack of code cache space.
Helper helper = new Helper();
for (int i = 0; i < 100_000; i++) {
helper.method(0, 0, 0, null);
}
}
// Only check this if compilation is disabled, otherwise the sweeper might have
// freed enough nmethods to allow for re-enabling compilation.
if (COMPILATION_DISABLED) {
Asserts.assertNotEquals(compilationActivityMode, 1 /* run_compilation*/,
"Compilation must be disabled when CodeCache(CodeHeap) overflows");
}
Asserts.assertNotEquals(compilationActivityMode, 1 /* run_compilation*/,
"Compilation must be disabled when CodeCache(CodeHeap) overflows");
}

private long getHeapSize() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2022, 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.
*
* 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.
*/

/*
* @test
* @requires vm.compiler2.enabled
* @bug 8279837
* @summary Tests infinite loop with region head in iteration split.
* @run main/othervm -Xcomp -XX:-TieredCompilation
* -XX:CompileCommand=compileonly,compiler.loopopts.TestIterationSplitWithRegionHead::test
* -XX:CompileCommand=dontinline,compiler.loopopts.TestIterationSplitWithRegionHead::*
* compiler.loopopts.TestIterationSplitWithRegionHead
*/

package compiler.loopopts;

public class TestIterationSplitWithRegionHead {

static boolean flagFalse = false;

public static void main(String[] args) {
test();
}

public static void test() {
// 1) The loop tree is built. We find that nested loop N2 is an infinite loop and add a NeverBranch
// to the inner loop to make it reachable. But the current loop tree does not have N2, yet. The
// resulting loop tree is:
//
// Loop: N0/N0 has_call has_sfpt
// Loop: N77/N121 has_call // N1 outer
// Loop: N77/N111 has_call sfpts={ 111 97 } // N1 inner
//
// 2) beautify_loops() finds that the outer loop head of N1 is shared and thus adds a new region
// in merge_many_backedges(). As a result, the loop tree is built again. This time, the NeverBranch
// in the inner loop of N2 allows that a loop tree can be built for it:
//
// Loop: N0/N0 has_call has_sfpt
// Loop: N216/N213 limit_check profile_predicated predicated has_call sfpts={ 111 97 } // N1 shared loop head
// Loop: N196/N201 sfpts={ 201 } // N2 inner loop now discovered with the new NeverBranch
//
// However, a LoopNode is only added by beautify_loops() which won't be called until the next iteration of loop opts.
// This means that we have a Region node (N196) as head in the loop tree which cannot be handled by iteration_split_impl()
// resulting in an assertion failure.

// Nested loop N1
while (flagFalse) {
while (dontInlineFalse()) {
}
}
dontInlineFalse();

// Nested loop N2
while (flagFalse) {
while (true) ; // Detected as infinite inner loop by C2 -> NeverBranch added
}
}

public static boolean dontInlineFalse() {
return false;
}
}

0 comments on commit 02eb28a

Please sign in to comment.