8289561: java/lang/instrument/NativeMethodPrefixAgent.java fails with "ERROR: Injection failure: java.lang.UnsupportedOperationException: Records requires ASM8"

Reviewed-by: lmesnik, cjplummer, sspitsyn
This commit is contained in:
Alex Menkov 2022-10-07 17:13:30 +00:00
parent a1747ef81a
commit c1166a304d
3 changed files with 17 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -45,6 +45,13 @@ class NativeMethodPrefixAgent {
static ClassFileTransformer t0, t1, t2; static ClassFileTransformer t0, t1, t2;
static Instrumentation inst; static Instrumentation inst;
private static Throwable agentError;
public static void checkErrors() {
if (agentError != null) {
throw new RuntimeException("Agent error", agentError);
}
}
static class Tr implements ClassFileTransformer { static class Tr implements ClassFileTransformer {
final String trname; final String trname;
@ -87,10 +94,12 @@ class NativeMethodPrefixAgent {
return redef? null : newcf; return redef? null : newcf;
} catch (Throwable ex) { } catch (Throwable ex) {
if (agentError == null) {
agentError = ex;
}
System.err.println("ERROR: Injection failure: " + ex); System.err.println("ERROR: Injection failure: " + ex);
ex.printStackTrace(); ex.printStackTrace();
System.err.println("Returning bad class file, to cause test failure"); return null;
return new byte[0];
} }
} }
return null; return null;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -48,6 +48,8 @@ public class NativeMethodPrefixApp implements StringIdCallback {
RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean(); RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
System.err.println(mxbean.getVmVendor()); System.err.println(mxbean.getVmVendor());
NativeMethodPrefixAgent.checkErrors();
for (int i = 0; i < gotIt.length; ++i) { for (int i = 0; i < gotIt.length; ++i) {
if (!gotIt[i]) { if (!gotIt[i]) {
throw new Exception("ERROR: Missing callback for transform " + i); throw new Exception("ERROR: Missing callback for transform " + i);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -124,7 +124,7 @@ public class Instrumentor {
} }
public synchronized Instrumentor addNativeMethodTrackingInjection(String prefix, Consumer<InstrHelper> injector) { public synchronized Instrumentor addNativeMethodTrackingInjection(String prefix, Consumer<InstrHelper> injector) {
instrumentingVisitor = new ClassVisitor(Opcodes.ASM7, instrumentingVisitor) { instrumentingVisitor = new ClassVisitor(Opcodes.ASM9, instrumentingVisitor) {
private final Set<Consumer<ClassVisitor>> wmGenerators = new HashSet<>(); private final Set<Consumer<ClassVisitor>> wmGenerators = new HashSet<>();
private String className; private String className;