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

@ -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.
*
* 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 Instrumentation inst;
private static Throwable agentError;
public static void checkErrors() {
if (agentError != null) {
throw new RuntimeException("Agent error", agentError);
}
}
static class Tr implements ClassFileTransformer {
final String trname;
@ -87,10 +94,12 @@ class NativeMethodPrefixAgent {
return redef? null : newcf;
} catch (Throwable ex) {
if (agentError == null) {
agentError = ex;
}
System.err.println("ERROR: Injection failure: " + ex);
ex.printStackTrace();
System.err.println("Returning bad class file, to cause test failure");
return new byte[0];
return null;
}
}
return null;

@ -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.
*
* 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();
System.err.println(mxbean.getVmVendor());
NativeMethodPrefixAgent.checkErrors();
for (int i = 0; i < gotIt.length; ++i) {
if (!gotIt[i]) {
throw new Exception("ERROR: Missing callback for transform " + i);

@ -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.
*
* 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) {
instrumentingVisitor = new ClassVisitor(Opcodes.ASM7, instrumentingVisitor) {
instrumentingVisitor = new ClassVisitor(Opcodes.ASM9, instrumentingVisitor) {
private final Set<Consumer<ClassVisitor>> wmGenerators = new HashSet<>();
private String className;