Path: blob/master/test/hotspot/jtreg/compiler/c1/Test8267042.java
64474 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package compiler.c1;2425import java.io.IOException;26import java.io.InterruptedIOException;2728/*29* @test30* @author Chris Cole31* @bug 826704232* @summary missing displaced_header initialization causes hangup33* @run main/othervm -XX:+TieredCompilation -XX:TieredStopAtLevel=134* -XX:-BackgroundCompilation -XX:CompileThreshold=135* -XX:CompileOnly=compiler.c1.Test8267042::write36* compiler.c1.Test826704237*/38public class Test8267042 {3940private static int DATA_SIZE = 4;4142private char buffer;43private boolean empty = true;4445public static void main(String[] args) {46Test8267042 test = new Test8267042();47test.run();48}4950private void run() {51System.out.println("Starting test");5253Thread writeThread = new Thread(new Runnable() {54@Override55public void run() {56char data[] = new char[DATA_SIZE];57try {58write(data, 0, data.length);59} catch (IOException e) {60e.printStackTrace();61}62}63});64writeThread.setDaemon(true);65writeThread.start();6667Thread readThread = new Thread(new Runnable() {68@Override69public void run() {70try {71for (int i = 0; i < DATA_SIZE; i++) {72read();73}74} catch (IOException e) {75e.printStackTrace();76}77}78});79readThread.setDaemon(true);80readThread.start();8182try {83writeThread.join(5000);84if (writeThread.isAlive()) {85throw new InternalError("write thread deadlocked");86}87readThread.join(5000);88if (readThread.isAlive()) {89throw new InternalError("read thread deadlocked");90}91} catch (InterruptedException e) {92throw new InternalError("unexpected InterrruptedException while waiting to join threads", e);93}94System.out.println("Test passed");95}9697synchronized void write(char data[], int offset, int length) throws IOException {98while (--length >= 0) {99getZeroOnStack(offset);100write(data[offset++]);101}102}103104synchronized void write(int c) throws IOException {105while (!empty) {106try {107wait(1000);108} catch (InterruptedException e) {109throw new InterruptedIOException();110}111}112buffer = (char) c;113empty = false;114notifyAll();115}116117public synchronized int read() throws IOException {118while (empty) {119try {120System.out.println("read() before wait");121wait(1000);122System.out.println("read() after wait");123} catch (InterruptedException e) {124throw new InterruptedIOException();125}126}127int value = buffer;128empty = true;129notifyAll();130return value;131}132133private void getZeroOnStack(int offset) {134int l1;135int l2;136int l3;137int l4;138int l5;139int l6;140int l7;141int l8;142int l9;143int l10;144int l11;145int l12;146int l13;147int l14;148int l15;149int l16;150151l1 = 0;152l2 = 0;153l3 = 0;154l4 = 0;155l5 = 0;156l6 = 0;157l7 = 0;158l8 = 0;159l9 = 0;160l10 = 0;161l11 = 0;162l12 = 0;163l13 = 0;164l14 = 0;165l15 = 0;166l16 = 0;167}168}169170171172