< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/classfile/ClassfileBytecodeProviderTest.java

Print this page




 178                                 throw new AssertionError(e);
 179                             }
 180                         }
 181                     }
 182                 } catch (IOException ex) {
 183                     Assert.fail(ex.toString());
 184                 }
 185             }
 186         }
 187     }
 188 
 189     private static boolean isInNativeImage(String className) {
 190         return className.startsWith("org.graalvm.nativeimage");
 191     }
 192 
 193     private static boolean isGSON(String className) {
 194         return className.contains("com.google.gson");
 195     }
 196 
 197     protected void checkClass(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, String className) throws ClassNotFoundException {




 198         Class<?> c = Class.forName(className, true, getClass().getClassLoader());
 199         ClassfileBytecodeProvider cbp = new ClassfileBytecodeProvider(metaAccess, snippetReflection);
 200         for (Method method : c.getDeclaredMethods()) {
 201             checkMethod(cbp, metaAccess, method);
 202         }
 203     }
 204 
 205     private static void checkMethod(ClassfileBytecodeProvider cbp, MetaAccessProvider metaAccess, Executable executable) {
 206         ResolvedJavaMethod method = metaAccess.lookupJavaMethod(executable);
 207         if (method.hasBytecodes()) {
 208             ResolvedJavaMethodBytecode expected = new ResolvedJavaMethodBytecode(method);
 209             Bytecode actual = getBytecode(cbp, method);
 210             new BytecodeComparer(expected, actual).compare();



 211         }
 212     }
 213 
 214     protected static Bytecode getBytecode(ClassfileBytecodeProvider cbp, ResolvedJavaMethod method) {
 215         try {
 216             return cbp.getBytecode(method);




 217         } catch (Throwable e) {
 218             throw new AssertionError(String.format("Error getting bytecode for %s", method.format("%H.%n(%p)")), e);
 219         }
 220     }
 221 
 222     static class BytecodeComparer {
 223 
 224         private Bytecode expected;
 225         private Bytecode actual;
 226         private ConstantPool eCp;
 227         private ConstantPool aCp;
 228         BytecodeStream eStream;
 229         BytecodeStream aStream;
 230         int bci = -1;
 231 
 232         BytecodeComparer(Bytecode expected, Bytecode actual) {
 233             this.expected = expected;
 234             this.actual = actual;
 235             this.eCp = expected.getConstantPool();
 236             this.aCp = actual.getConstantPool();




 178                                 throw new AssertionError(e);
 179                             }
 180                         }
 181                     }
 182                 } catch (IOException ex) {
 183                     Assert.fail(ex.toString());
 184                 }
 185             }
 186         }
 187     }
 188 
 189     private static boolean isInNativeImage(String className) {
 190         return className.startsWith("org.graalvm.nativeimage");
 191     }
 192 
 193     private static boolean isGSON(String className) {
 194         return className.contains("com.google.gson");
 195     }
 196 
 197     protected void checkClass(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, String className) throws ClassNotFoundException {
 198         if (className.equals("jdk.vm.ci.services.JVMCIClassLoaderFactory")) {
 199             // JVMCIClassLoaderFactory must only be initialized by the VM
 200             return;
 201         }
 202         Class<?> c = Class.forName(className, true, getClass().getClassLoader());
 203         ClassfileBytecodeProvider cbp = new ClassfileBytecodeProvider(metaAccess, snippetReflection);
 204         for (Method method : c.getDeclaredMethods()) {
 205             checkMethod(cbp, metaAccess, method);
 206         }
 207     }
 208 
 209     private static void checkMethod(ClassfileBytecodeProvider cbp, MetaAccessProvider metaAccess, Executable executable) {
 210         ResolvedJavaMethod method = metaAccess.lookupJavaMethod(executable);
 211         if (method.hasBytecodes()) {

 212             Bytecode actual = getBytecode(cbp, method);
 213             if (actual != null) {
 214                 ResolvedJavaMethodBytecode expected = new ResolvedJavaMethodBytecode(method);
 215                 new BytecodeComparer(expected, actual).compare();
 216             }
 217         }
 218     }
 219 
 220     protected static Bytecode getBytecode(ClassfileBytecodeProvider cbp, ResolvedJavaMethod method) {
 221         try {
 222             return cbp.getBytecode(method);
 223         } catch (UnsupportedClassVersionError e) {
 224             // This can happen when a library containing old class files
 225             // is bundled into a Graal jar (GR-12672).
 226             return null;
 227         } catch (Throwable e) {
 228             throw new AssertionError(String.format("Error getting bytecode for %s", method.format("%H.%n(%p)")), e);
 229         }
 230     }
 231 
 232     static class BytecodeComparer {
 233 
 234         private Bytecode expected;
 235         private Bytecode actual;
 236         private ConstantPool eCp;
 237         private ConstantPool aCp;
 238         BytecodeStream eStream;
 239         BytecodeStream aStream;
 240         int bci = -1;
 241 
 242         BytecodeComparer(Bytecode expected, Bytecode actual) {
 243             this.expected = expected;
 244             this.actual = actual;
 245             this.eCp = expected.getConstantPool();
 246             this.aCp = actual.getConstantPool();


< prev index next >