Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/BacktraceFieldTest.java
38855 views
/*1* Copyright (c) 2001, 2002, 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*/2223/**24* @test25* @bug 444667726* @summary debuggee crashes when debugging under jbuilder27*28* @author jjh29*30* @run build TestScaffold VMConnection TargetListener TargetAdapter31* @run compile -g BacktraceFieldTest.java32* @run main BacktraceFieldTest33*/3435/*36* The fix for this bug filters out the backtrace field from the list37* of fields for java.lang.Throwable.38* This test verifies that this really happens, and also verifies that the fix39* doesn't incorrectly discard other fields.40*/4142import com.sun.jdi.*;43import com.sun.jdi.event.*;44import com.sun.jdi.request.*;4546import java.util.*;4748/********** target program **********/4950class Testy {51/*52* This is used to verify that the fix doesn't filter out fields that it53* shouldn't. 7 is an abitrary number, and this isn't a definitive54* test; the fix could conceivably filter out the 89th field of a class55* named Foo.56* To verify that this part of this test works, first uncomment the field857* line and verify that the test fails, and then rename a field to xxx and58* verify that the test fails.59*/60int field1;61int field2;62int field3;63int field4;64int field5;65int field6;66final static int field7 = 7; // Value is the number of fields.67//int field8;6869Testy() {70}71}727374class BacktraceFieldTarg {75public static void gus() {76}7778public static void main(String[] args) {79Testy myTesty = new Testy();80try {81throw new RuntimeException("jjException");82} catch (Exception ee) {83gus();84System.out.println("debuggee: Exception: " + ee);85}86}87}8889/********** test program **********/9091public class BacktraceFieldTest extends TestScaffold {92ThreadReference mainThread;9394BacktraceFieldTest (String args[]) {95super(args);96}9798public static void main(String[] args) throws Exception {99new BacktraceFieldTest(args).startTests();100}101102/********** test core **********/103104protected void runTests() throws Exception {105/*106* Get to the top of gus()107* to determine mainThread108*/109BreakpointEvent bpe = startTo("BacktraceFieldTarg", "gus", "()V");110mainThread = bpe.thread();111112/*113* We are now one frame below the exception frame that contains114* our ee var.115*/116StackFrame myFrame = mainThread.frame(1);117118LocalVariable lv = myFrame.visibleVariableByName("ee");119println("BT: lv = " + lv);120println("BT: lvType = " + lv.typeName());121122List allFields = ((ReferenceType)(lv.type())).allFields();123println("BT: allFields = " + allFields);124125/*126* Search through the fields of ee to verify that127* java.lang.Throwable.backtrace isn't there.128*/129Iterator iter = allFields.iterator();130while(iter.hasNext()) {131Field ff = (Field)iter.next();132if (ff.toString().equals("java.lang.Throwable.backtrace")) {133failure("ERROR: java.lang.Throwable.backtrace field not filtered out.");134135/*136* If you want to experience the segv this bug causes, change137* this test to 1 == 1 and run it with jdk 1.4, build 74 or earlier138*/139if (1 == 0) {140// The following code will show the segv that this can cause.141ObjectReference myVal = (ObjectReference)myFrame.getValue(lv);142println("BT: myVal = " + myVal);143144ArrayReference backTraceVal = null;145backTraceVal = (ArrayReference)myVal.getValue(ff);146println("BT: backTraceVal = " + backTraceVal);147148ArrayReference secondVal = (ArrayReference)backTraceVal.getValue(1);149println("BT: secondVal = " + secondVal);150151Object x2Val = (Object)secondVal.getValue(0);152println("BT: x2Val = " + x2Val);153154ArrayReference firstVal = (ArrayReference)backTraceVal.getValue(0);155println("BT: firstVal = " + firstVal);156157// The segv happens here.158Object xVal = (Object)firstVal.getValue(0);159println("BT: xVal = " + xVal);160}161break;162}163}164165// Next, verify that we don't accidently discard a field that we shouldn't166167if (!testFailed) {168lv = myFrame.visibleVariableByName("myTesty");169170allFields = ((ReferenceType)(lv.type())).allFields();171println("BT: allFields = " + allFields);172173if (allFields.size() != Testy.field7) {174failure("ERROR: wrong number of fields; expected " + Testy.field7 + ", Got " + allFields.size());175} else {176iter = allFields.iterator();177while(iter.hasNext()) {178String fieldName = ((Field)iter.next()).toString();179if (!fieldName.startsWith("Testy.field", 0)) {180failure("ERROR: Found bogus field: " + fieldName.toString());181}182}183}184}185186listenUntilVMDisconnect();187188/*189* deal with results of test190* if anything has called failure("foo") testFailed will be true191*/192if (!testFailed) {193println("BacktraceFieldTest: passed");194} else {195throw new Exception("BacktraceFieldTest: failed");196}197}198}199200201