Path: blob/master/test/jdk/com/sun/jdi/ConstantPoolInfoGC.java
41149 views
/*1* Copyright (c) 2016, 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 682262726* @summary Test that ReferenceType.constantPool does not produce an NPE27* @author Egor Ushakov28*29* @modules jdk.jdi/com.sun.tools.jdi:+open30*31* @run build TestScaffold VMConnection32* @run compile -g ConstantPoolInfoGC.java33* @run main/othervm ConstantPoolInfoGC34*/3536import com.sun.jdi.ReferenceType;37import com.sun.tools.jdi.ReferenceTypeImpl;3839import java.lang.ref.Reference;40import java.lang.reflect.Field;41import java.util.Arrays;4243/********** target program **********/4445class ConstantPoolGCTarg {46public static void main(String[] args){47System.out.println("Anything");48}49}5051/********** test program **********/5253public class ConstantPoolInfoGC extends TestScaffold {54ReferenceType targetClass;5556ConstantPoolInfoGC(String args[]) {57super(args);58}5960public static void main(String[] args) throws Exception {61new ConstantPoolInfoGC(args).startTests();62}6364/********** test core **********/6566protected void runTests() throws Exception {67targetClass = startToMain("ConstantPoolGCTarg").location().declaringType();6869if (vm().canGetConstantPool()) {70byte[] cpbytes = targetClass.constantPool();7172// imitate SoftReference cleared73Field constantPoolBytesRef = ReferenceTypeImpl.class.getDeclaredField("constantPoolBytesRef");74constantPoolBytesRef.setAccessible(true);75Reference softRef = (Reference) constantPoolBytesRef.get(targetClass);76softRef.clear();7778byte[] cpbytes2 = targetClass.constantPool();79if (!Arrays.equals(cpbytes, cpbytes2)) {80failure("Consequent constantPool results vary, first was : " + cpbytes + ", now: " + cpbytes2);81};8283} else {84System.out.println("can get constant pool version not supported");85}868788/*89* resume until end90*/91listenUntilVMDisconnect();9293/*94* deal with results of test95* if anything has called failure("foo") testFailed will be true96*/97if (!testFailed) {98println("ConstantPoolInfoGC: passed");99} else {100throw new Exception("ConstantPoolInfoGC: failed");101}102}103}104105106