1 /* 2 * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package compiler.c1; 25 26 import java.io.IOException; 27 import java.io.InterruptedIOException; 28 29 /* 30 * @test 31 * @author Chris Cole 32 * @bug 8267042 33 * @summary missing displaced_header initialization causes hangup 34 * @run main/othervm -XX:+TieredCompilation -XX:TieredStopAtLevel=1 35 * -XX:-BackgroundCompilation -XX:CompileThreshold=1 36 * -XX:CompileOnly=compiler.c1.Test8267042::write 37 * compiler.c1.Test8267042 38 */ 39 public class Test8267042 { 40 41 private static int DATA_SIZE = 4; 42 43 private char buffer; 44 private boolean empty = true; 45 main(String[] args)46 public static void main(String[] args) { 47 Test8267042 test = new Test8267042(); 48 test.run(); 49 } 50 run()51 private void run() { 52 System.out.println("Starting test"); 53 54 Thread writeThread = new Thread(new Runnable() { 55 @Override 56 public void run() { 57 char data[] = new char[DATA_SIZE]; 58 try { 59 write(data, 0, data.length); 60 } catch (IOException e) { 61 e.printStackTrace(); 62 } 63 } 64 }); 65 writeThread.setDaemon(true); 66 writeThread.start(); 67 68 Thread readThread = new Thread(new Runnable() { 69 @Override 70 public void run() { 71 try { 72 for (int i = 0; i < DATA_SIZE; i++) { 73 read(); 74 } 75 } catch (IOException e) { 76 e.printStackTrace(); 77 } 78 } 79 }); 80 readThread.setDaemon(true); 81 readThread.start(); 82 83 try { 84 writeThread.join(5000); 85 if (writeThread.isAlive()) { 86 throw new InternalError("write thread deadlocked"); 87 } 88 readThread.join(5000); 89 if (readThread.isAlive()) { 90 throw new InternalError("read thread deadlocked"); 91 } 92 } catch (InterruptedException e) { 93 throw new InternalError("unexpected InterrruptedException while waiting to join threads", e); 94 } 95 System.out.println("Test passed"); 96 } 97 write(char data[], int offset, int length)98 synchronized void write(char data[], int offset, int length) throws IOException { 99 while (--length >= 0) { 100 getZeroOnStack(offset); 101 write(data[offset++]); 102 } 103 } 104 write(int c)105 synchronized void write(int c) throws IOException { 106 while (!empty) { 107 try { 108 wait(1000); 109 } catch (InterruptedException e) { 110 throw new InterruptedIOException(); 111 } 112 } 113 buffer = (char) c; 114 empty = false; 115 notifyAll(); 116 } 117 read()118 public synchronized int read() throws IOException { 119 while (empty) { 120 try { 121 System.out.println("read() before wait"); 122 wait(1000); 123 System.out.println("read() after wait"); 124 } catch (InterruptedException e) { 125 throw new InterruptedIOException(); 126 } 127 } 128 int value = buffer; 129 empty = true; 130 notifyAll(); 131 return value; 132 } 133 getZeroOnStack(int offset)134 private void getZeroOnStack(int offset) { 135 int l1; 136 int l2; 137 int l3; 138 int l4; 139 int l5; 140 int l6; 141 int l7; 142 int l8; 143 int l9; 144 int l10; 145 int l11; 146 int l12; 147 int l13; 148 int l14; 149 int l15; 150 int l16; 151 152 l1 = 0; 153 l2 = 0; 154 l3 = 0; 155 l4 = 0; 156 l5 = 0; 157 l6 = 0; 158 l7 = 0; 159 l8 = 0; 160 l9 = 0; 161 l10 = 0; 162 l11 = 0; 163 l12 = 0; 164 l13 = 0; 165 l14 = 0; 166 l15 = 0; 167 l16 = 0; 168 } 169 } 170 171