|
Java example source code file (T7190862.java)
The T7190862.java Java example source code
/*
* @test /nodynamiccopyright/
* @bug 7190862 7109747
* @summary javap shows an incorrect type for operands if the 'wide' prefix is used
*/
import com.sun.source.util.JavacTask;
import com.sun.tools.javap.JavapFileManager;
import com.sun.tools.javap.JavapTask;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.SimpleJavaFileObject;
import javax.tools.ToolProvider;
public class T7190862 {
enum TypeWideInstructionMap {
INT("int", new String[]{"istore_w", "iload_w"}),
LONG("long", new String[]{"lstore_w", "lload_w"}),
FLOAT("float", new String[]{"fstore_w", "fload_w"}),
DOUBLE("double", new String[]{"dstore_w", "dload_w"}),
OBJECT("Object", new String[]{"astore_w", "aload_w"});
String type;
String[] instructions;
TypeWideInstructionMap(String type, String[] instructions) {
this.type = type;
this.instructions = instructions;
}
}
JavaSource source;
public static void main(String[] args) {
JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
new T7190862().run(comp);
}
private void run(JavaCompiler comp) {
String code;
for (TypeWideInstructionMap typeInstructionMap: TypeWideInstructionMap.values()) {
if (typeInstructionMap != TypeWideInstructionMap.OBJECT) {
code = createWideLocalSource(typeInstructionMap.type, 300);
} else {
code = createWideLocalSourceForObject(300);
}
source = new JavaSource(code);
compile(comp);
check(typeInstructionMap.instructions);
}
//an extra test for the iinc instruction
code = createIincSource();
source = new JavaSource(code);
compile(comp);
check(new String[]{"iinc_w"});
}
private void compile(JavaCompiler comp) {
JavacTask ct = (JavacTask)comp.getTask(null, null, null, null, null, Arrays.asList(source));
try {
if (!ct.call()) {
throw new AssertionError("Error thrown when compiling the following source:\n" + source.getCharContent(true));
}
} catch (Throwable ex) {
throw new AssertionError("Error thrown when compiling the following source:\n" + source.getCharContent(true));
}
}
private void check(String[] instructions) {
String out = javap(Arrays.asList("-c"), Arrays.asList("Test.class"));
for (String line: out.split(System.getProperty("line.separator"))) {
line = line.trim();
for (String instruction: instructions) {
if (line.contains(instruction) && line.contains("#")) {
throw new Error("incorrect type for operands for instruction " + instruction);
}
}
}
}
private String javap(List<String> args, List
Other Java examples (source code examples)Here is a short list of links related to this Java T7190862.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.