/* * Copyright (c) 2005, 2015, 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.
*/
class ConstantPoolTarg { publicstaticvoid main(String[] args){
System.out.println("Howdy!"); // don't change the string value "Howdy!" it is // used to test the constant pool entry
}
}
publicstaticvoid main(String[] args) throws Exception { new ConstantPoolInfo(args).startTests();
}
/********** test core **********/
protectedvoid runTests() throws Exception { /* * Get to the top of main() * to determine targetClass and mainThread
*/
BreakpointEvent bpe = startToMain("ConstantPoolTarg");
targetClass = bpe.location().declaringType();
mainThread = bpe.thread();
/* Test constant pool apis
*/ if (vm().canGetClassFileVersion()) { if (expectedMajorVersion != targetClass.majorVersion()) {
failure("unexpected major version: actual value: " + targetClass.majorVersion()
+ "expected value :" + expectedMajorVersion);
} if (expectedMinorVersion != targetClass.minorVersion()) {
failure("unexpected minor version: actual value: " + targetClass.minorVersion()
+ "expected value :" + expectedMinorVersion);
}
} else {
System.out.println("can get class version not supported");
}
if (expectedCpoolCount != cpool_count) {
failure("unexpected constant pool count: actual value: " + cpool_count
+ "expected value :" + expectedCpoolCount);
}
} else {
System.out.println("can get constant pool version not supported");
}
/* * resume until end
*/
listenUntilVMDisconnect();
/* * deal with results of test * if anything has called failure("foo") testFailed will be true
*/ if (!testFailed) {
println("ConstantPoolInfo: passed");
} else { thrownew Exception("ConstantPoolInfo: failed");
}
}
publicvoid printcp() throws IOException { boolean found = false;
ByteArrayInputStream bytesStream = new ByteArrayInputStream(cpbytes);
DataInputStream in = new DataInputStream(bytesStream); for (int i = 1; i < cpool_count; i++) { int tag = in.readByte();
System.out.print("const #" + i + ": "); switch(tag) { case CONSTANT_UTF8:
String str=in.readUTF();
System.out.println("Asciz " + str); // "Howdy!" is an expected constant pool entry // of test program. It should exist. if (str.compareTo("Howdy!") == 0) {
found = true;
} break; case CONSTANT_INTEGER:
System.out.println("int " + in.readInt()); break; case CONSTANT_FLOAT:
System.out.println("Float " + in.readFloat()); break; case CONSTANT_LONG:
System.out.println("Long " + in.readLong()); break; case CONSTANT_DOUBLE:
System.out.println("Double " + in.readDouble()); break; case CONSTANT_CLASS:
System.out.println("Class " + in.readUnsignedShort()); break; case CONSTANT_STRING:
System.out.println("String " + in.readUnsignedShort()); break; case CONSTANT_FIELD:
System.out.println("Field " + in.readUnsignedShort() + " " + in.readUnsignedShort()); break; case CONSTANT_METHOD:
System.out.println("Method " + in.readUnsignedShort() + " " + in.readUnsignedShort()); break; case CONSTANT_INTERFACEMETHOD:
System.out.println("InterfaceMethod " + in.readUnsignedShort() + " " + in.readUnsignedShort()); break; case CONSTANT_NAMEANDTYPE:
System.out.println("NameAndType " + in.readUnsignedShort() + " " + in.readUnsignedShort()); break; case 0: default:
System.out.println("class format error");
}
}
if (!found) {
failure("expected string \"Howdy!\" not found in constant pool");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.