Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/hotspot/share/prims/jvmtiRedefineClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,8 @@ jvmtiError VM_RedefineClasses::load_new_class_versions() {
} else {
return JVMTI_ERROR_INTERNAL;
}
} else if (res != JVMTI_ERROR_NONE) {
return res;
}

#ifdef ASSERT
Expand Down Expand Up @@ -2045,7 +2047,7 @@ bool VM_RedefineClasses::rewrite_cp_refs_in_record_attribute(InstanceKlass* scra
AnnotationArray* type_annotations = component->type_annotations();
if (type_annotations != nullptr && type_annotations->length() != 0) {
int byte_i = 0; // byte index into annotations
if (!rewrite_cp_refs_in_annotations_typeArray(type_annotations, byte_i)) {
if (!rewrite_cp_refs_in_type_annotations_typeArray(type_annotations, byte_i, "record_info")) {
log_debug(redefine, class, annotation)("bad record_component_type_annotations at %d", i);
// propagate failure back to caller
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2026, Datadog, Inc. 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.
*/

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@MyTypeAnnotation
public record MyRecord(@MyTypeUseAnnotation String filter) {
public static MyRecord parse(String param) {
if (param == null) {
throw new IllegalArgumentException("Filter cannot be null");
}
return new MyRecord(param);
}
}

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@interface MyTypeAnnotation {
}

@Target({ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@interface MyTypeUseAnnotation {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2026, Datadog, Inc. 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.
*/

/*
* @test
* @bug 8376185
* @summary Class retransformation on a record type annotation
* @comment This is will rewrite the constant pool and process
* @comment the type annotation
* @library /test/lib
* @modules java.base/jdk.internal.misc
* @modules java.compiler
* java.instrument
* @compile ../NamedBuffer.java
* @compile altered/MyRecord.jcod
* @run driver jdk.test.lib.helpers.ClassFileInstaller MyRecord
* @compile MyRecord.java
* @run main RedefineClassHelper
* @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine*=debug TestRetransformRecord
*/

/*
* This test is loading a record with type annotation first, then by
* calling retransformClasses, we inject a slightly different record classfile
* where just some constants from the constant pools were swapped.
* It triggers, during the retransformation, a rewrite of the constant pool
* calling VM_RedefineClasses::rewrite_cp_refs_in_record_attribute method.
*/
import java.io.File;
import java.io.FileInputStream;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.security.ProtectionDomain;

public class TestRetransformRecord {
static final String SRC = System.getProperty("test.src");
static final String DEST = System.getProperty("test.classes");

public static void main(String[] args) throws Exception {
MyRecord.parse("foo");
File clsfile = new File("MyRecord.class");
byte[] buf = null;
try (FileInputStream str = new FileInputStream(clsfile)) {
buf = NamedBuffer.loadBufferFromStream(str);
}
Instrumentation inst = RedefineClassHelper.instrumentation;
inst.addTransformer(new IdentityTransformer("MyRecord", buf), true);
inst.retransformClasses(MyRecord.class);
System.out.println(MyRecord.parse("foo"));
}
}

class IdentityTransformer implements ClassFileTransformer {
private final String className;
private final byte[] buffer;

public IdentityTransformer(String className, byte[] buffer) {
this.className = className;
this.buffer = buffer;
}

@Override
public byte[] transform(ClassLoader loader,
String classPath,
Class<?> classBeingRedefined,
ProtectionDomain protectionDomain,
byte[] classfileBuffer) {
if (classPath != null && classPath.equals(className.replace('.', '/'))) {
System.out.println("Transforming " + className);
return buffer;
}
return null;
}
}
Loading