Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/back/ObjectReferenceImpl.c
38765 views
/*1* Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "util.h"26#include "ObjectReferenceImpl.h"27#include "commonRef.h"28#include "inStream.h"29#include "outStream.h"3031static jboolean32referenceType(PacketInputStream *in, PacketOutputStream *out)33{34JNIEnv *env;35jobject object;3637env = getEnv();3839object = inStream_readObjectRef(env, in);40if (inStream_error(in)) {41return JNI_TRUE;42}4344WITH_LOCAL_REFS(env, 1) {4546jbyte tag;47jclass clazz;4849clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);50tag = referenceTypeTag(clazz);5152(void)outStream_writeByte(out, tag);53(void)outStream_writeObjectRef(env, out, clazz);5455} END_WITH_LOCAL_REFS(env);5657return JNI_TRUE;58}5960static jboolean61getValues(PacketInputStream *in, PacketOutputStream *out)62{63sharedGetFieldValues(in, out, JNI_FALSE);64return JNI_TRUE;65}666768static jvmtiError69readFieldValue(JNIEnv *env, PacketInputStream *in, jclass clazz,70jobject object, jfieldID field, char *signature)71{72jvalue value;73jvmtiError error;7475switch (signature[0]) {76case JDWP_TAG(ARRAY):77case JDWP_TAG(OBJECT):78value.l = inStream_readObjectRef(env, in);79JNI_FUNC_PTR(env,SetObjectField)(env, object, field, value.l);80break;8182case JDWP_TAG(BYTE):83value.b = inStream_readByte(in);84JNI_FUNC_PTR(env,SetByteField)(env, object, field, value.b);85break;8687case JDWP_TAG(CHAR):88value.c = inStream_readChar(in);89JNI_FUNC_PTR(env,SetCharField)(env, object, field, value.c);90break;9192case JDWP_TAG(FLOAT):93value.f = inStream_readFloat(in);94JNI_FUNC_PTR(env,SetFloatField)(env, object, field, value.f);95break;9697case JDWP_TAG(DOUBLE):98value.d = inStream_readDouble(in);99JNI_FUNC_PTR(env,SetDoubleField)(env, object, field, value.d);100break;101102case JDWP_TAG(INT):103value.i = inStream_readInt(in);104JNI_FUNC_PTR(env,SetIntField)(env, object, field, value.i);105break;106107case JDWP_TAG(LONG):108value.j = inStream_readLong(in);109JNI_FUNC_PTR(env,SetLongField)(env, object, field, value.j);110break;111112case JDWP_TAG(SHORT):113value.s = inStream_readShort(in);114JNI_FUNC_PTR(env,SetShortField)(env, object, field, value.s);115break;116117case JDWP_TAG(BOOLEAN):118value.z = inStream_readBoolean(in);119JNI_FUNC_PTR(env,SetBooleanField)(env, object, field, value.z);120break;121}122123error = JVMTI_ERROR_NONE;124if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {125error = AGENT_ERROR_JNI_EXCEPTION;126}127128return error;129}130131static jboolean132setValues(PacketInputStream *in, PacketOutputStream *out)133{134JNIEnv *env;135jint count;136jvmtiError error;137jobject object;138139env = getEnv();140141object = inStream_readObjectRef(env, in);142if (inStream_error(in)) {143return JNI_TRUE;144}145count = inStream_readInt(in);146if (inStream_error(in)) {147return JNI_TRUE;148}149150error = JVMTI_ERROR_NONE;151152WITH_LOCAL_REFS(env, count + 1) {153154jclass clazz;155156clazz = JNI_FUNC_PTR(env,GetObjectClass)(env, object);157158if (clazz != NULL ) {159160int i;161162for (i = 0; (i < count) && !inStream_error(in); i++) {163164jfieldID field;165char *signature = NULL;166167field = inStream_readFieldID(in);168if (inStream_error(in))169break;170171error = fieldSignature(clazz, field, NULL, &signature, NULL);172if (error != JVMTI_ERROR_NONE) {173break;174}175176error = readFieldValue(env, in, clazz, object, field, signature);177jvmtiDeallocate(signature);178179if (error != JVMTI_ERROR_NONE) {180break;181}182}183}184185if (error != JVMTI_ERROR_NONE) {186outStream_setError(out, map2jdwpError(error));187}188189} END_WITH_LOCAL_REFS(env);190191return JNI_TRUE;192}193194static jboolean195monitorInfo(PacketInputStream *in, PacketOutputStream *out)196{197JNIEnv *env;198jobject object;199200env = getEnv();201202object = inStream_readObjectRef(env, in);203if (inStream_error(in)) {204return JNI_TRUE;205}206207WITH_LOCAL_REFS(env, 1) {208209jvmtiError error;210jvmtiMonitorUsage info;211212(void)memset(&info, 0, sizeof(info));213error = JVMTI_FUNC_PTR(gdata->jvmti,GetObjectMonitorUsage)214(gdata->jvmti, object, &info);215if (error != JVMTI_ERROR_NONE) {216outStream_setError(out, map2jdwpError(error));217} else {218int i;219(void)outStream_writeObjectRef(env, out, info.owner);220(void)outStream_writeInt(out, info.entry_count);221(void)outStream_writeInt(out, info.waiter_count);222for (i = 0; i < info.waiter_count; i++) {223(void)outStream_writeObjectRef(env, out, info.waiters[i]);224}225}226227if (info.waiters != NULL )228jvmtiDeallocate(info.waiters);229230} END_WITH_LOCAL_REFS(env);231232return JNI_TRUE;233}234235static jboolean236invokeInstance(PacketInputStream *in, PacketOutputStream *out)237{238return sharedInvoke(in, out);239}240241static jboolean242disableCollection(PacketInputStream *in, PacketOutputStream *out)243{244jlong id;245jvmtiError error;246247id = inStream_readObjectID(in);248if (inStream_error(in)) {249return JNI_TRUE;250}251252error = commonRef_pin(id);253if (error != JVMTI_ERROR_NONE) {254outStream_setError(out, map2jdwpError(error));255}256257return JNI_TRUE;258}259260static jboolean261enableCollection(PacketInputStream *in, PacketOutputStream *out)262{263jvmtiError error;264jlong id;265266id = inStream_readObjectID(in);267if (inStream_error(in)) {268return JNI_TRUE;269}270271error = commonRef_unpin(id);272if (error != JVMTI_ERROR_NONE) {273outStream_setError(out, map2jdwpError(error));274}275276return JNI_TRUE;277}278279static jboolean280isCollected(PacketInputStream *in, PacketOutputStream *out)281{282jobject ref;283jlong id;284JNIEnv *env;285286env = getEnv();287id = inStream_readObjectID(in);288if (inStream_error(in)) {289return JNI_TRUE;290}291292if (id == NULL_OBJECT_ID) {293outStream_setError(out, JDWP_ERROR(INVALID_OBJECT));294return JNI_TRUE;295}296297ref = commonRef_idToRef(env, id);298(void)outStream_writeBoolean(out, (jboolean)(ref == NULL));299300commonRef_idToRef_delete(env, ref);301302return JNI_TRUE;303}304305306static jboolean307referringObjects(PacketInputStream *in, PacketOutputStream *out)308{309jobject object;310jint maxReferrers;311JNIEnv *env;312313env = getEnv();314315if (gdata->vmDead) {316outStream_setError(out, JDWP_ERROR(VM_DEAD));317return JNI_TRUE;318}319320object = inStream_readObjectRef(env,in);321if (inStream_error(in)) {322return JNI_TRUE;323}324325maxReferrers = inStream_readInt(in);326if (inStream_error(in)) {327return JNI_TRUE;328}329330WITH_LOCAL_REFS(env, 1) {331jvmtiError error;332ObjectBatch referrerBatch;333334error = objectReferrers(object, &referrerBatch, maxReferrers);335if (error != JVMTI_ERROR_NONE) {336outStream_setError(out, map2jdwpError(error));337} else {338int kk;339340(void)outStream_writeInt(out, referrerBatch.count);341for (kk = 0; kk < referrerBatch.count; kk++) {342jobject ref;343344ref = referrerBatch.objects[kk];345(void)outStream_writeByte(out, specificTypeKey(env, ref));346(void)outStream_writeObjectRef(env, out, ref);347}348jvmtiDeallocate(referrerBatch.objects);349}350} END_WITH_LOCAL_REFS(env);351return JNI_TRUE;352}353354void *ObjectReference_Cmds[] = { (void *)10355,(void *)referenceType356,(void *)getValues357,(void *)setValues358,(void *)NULL /* no longer used */359,(void *)monitorInfo360,(void *)invokeInstance361,(void *)disableCollection362,(void *)enableCollection363,(void *)isCollected364,(void *)referringObjects365};366367368