8265795: vmTestbase/nsk/jvmti/AttachOnDemand/attach022/TestDescription.java fails when running with JEP 416

Reviewed-by: sspitsyn, dholmes
This commit is contained in:
Leonid Mesnik 2021-11-22 17:11:34 +00:00
parent 22f12ac429
commit 33e2a518eb
4 changed files with 146 additions and 2 deletions
src/hotspot/share/prims
test/hotspot/jtreg

@ -41,6 +41,7 @@
#include "oops/objArrayOop.inline.hpp"
#include "oops/oop.inline.hpp"
#include "oops/typeArrayOop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/unsafe.hpp"
#include "runtime/globals.hpp"
#include "runtime/handles.inline.hpp"
@ -329,6 +330,7 @@ UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
////// Allocation requests
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
JvmtiVMObjectAllocEventCollector oam;
instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(cls), CHECK_NULL);
return JNIHandles::make_local(THREAD, i);
} UNSAFE_END

@ -38,8 +38,6 @@
#
#############################################################################
vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/TestDescription.java 8265795 generic-all
vmTestbase/nsk/jvmti/AttachOnDemand/attach022/TestDescription.java 8265795 generic-all
vmTestbase/nsk/jdi/ObjectReference/referringObjects/referringObjects002/referringObjects002.java 8265796 generic-all
#############################################################################

@ -0,0 +1,53 @@
/*
* Copyright (c) 2021, 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
* 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
* @summary Verifies that a VMObjectAlloc event is generated for object created using MethodHandle
* @requires vm.jvmti
* @run main/othervm/native -agentlib:VMObjectAlloc VMObjectAllocTest
*/
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
public class VMObjectAllocTest {
private static native int getNumberOfAllocation();
public VMObjectAllocTest(String str) {
}
public static void main(String[] args) throws Throwable {
MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
MethodType mt = MethodType.methodType(void.class, String.class);
MethodHandle mh = publicLookup.findConstructor(VMObjectAllocTest.class, mt);
mh.invoke("str");
if (getNumberOfAllocation() != 1) {
throw new Exception("Number of allocation != 1");
}
}
}

@ -0,0 +1,91 @@
/*
* Copyright (c) 2021, 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
* 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.
*/
#include <string.h>
#include "jvmti.h"
extern "C" {
static int number_of_allocation = 0;
extern JNIEXPORT void JNICALL
VMObjectAlloc(jvmtiEnv *jvmti,
JNIEnv* jni,
jthread thread,
jobject object,
jclass cls,
jlong size) {
char *signature = NULL;
jvmtiError err = jvmti->GetClassSignature(cls, &signature, NULL);
if (err != JVMTI_ERROR_NONE) {
jni->FatalError("Failed during the GetClassSignature call");
}
printf("VMObjectAlloc called for %s\n", signature);
if (!strcmp(signature, "LVMObjectAllocTest;")) {
number_of_allocation++;
}
}
JNIEXPORT jint JNICALL
Java_VMObjectAllocTest_getNumberOfAllocation(JNIEnv *env, jclass cls) {
return number_of_allocation;
}
extern JNIEXPORT jint JNICALL
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
jvmtiEnv *jvmti;
jvmtiEventCallbacks callbacks;
jvmtiError err;
jvmtiCapabilities caps;
if (jvm->GetEnv((void **) &jvmti, JVMTI_VERSION) != JNI_OK) {
return JNI_ERR;
}
memset(&callbacks, 0, sizeof(callbacks));
callbacks.VMObjectAlloc = &VMObjectAlloc;
memset(&caps, 0, sizeof(caps));
caps.can_generate_vm_object_alloc_events = 1;
err = jvmti->AddCapabilities( &caps);
if (err != JVMTI_ERROR_NONE) {
return JNI_ERR;
}
err = jvmti->SetEventCallbacks(&callbacks, sizeof(jvmtiEventCallbacks));
if (err != JVMTI_ERROR_NONE) {
return JNI_ERR;
}
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC , NULL);
if (err != JVMTI_ERROR_NONE) {
return JNI_ERR;
}
return JNI_OK;
}
} //extern "C"