Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/back/StackFrameImpl.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 "StackFrameImpl.h"27#include "inStream.h"28#include "outStream.h"29#include "threadControl.h"30#include "FrameID.h"3132static jdwpError33validateThreadFrame(jthread thread, FrameID frame)34{35jvmtiError error;36jdwpError serror;37jint count;38error = threadControl_suspendCount(thread, &count);39if ( error == JVMTI_ERROR_NONE ) {40if ( count > 0 ) {41serror = validateFrameID(thread, frame);42} else {43serror = JDWP_ERROR(THREAD_NOT_SUSPENDED);44}45} else {46serror = map2jdwpError(error);47}48return serror;49}5051static jdwpError52writeVariableValue(JNIEnv *env, PacketOutputStream *out, jthread thread,53FrameNumber fnum, jint slot, jbyte typeKey)54{55jvmtiError error;56jvalue value;5758if (isObjectTag(typeKey)) {5960WITH_LOCAL_REFS(env, 1) {6162error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalObject)63(gdata->jvmti, thread, fnum, slot, &value.l);6465if (error != JVMTI_ERROR_NONE) {66outStream_setError(out, map2jdwpError(error));67} else {68(void)outStream_writeByte(out, specificTypeKey(env, value.l));69(void)outStream_writeObjectRef(env, out, value.l);70}7172} END_WITH_LOCAL_REFS(env);7374} else {75/*76* For primitive types, the type key is bounced back as is.77*/78(void)outStream_writeByte(out, typeKey);79switch (typeKey) {80case JDWP_TAG(BYTE): {81jint intValue;82error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)83(gdata->jvmti, thread, fnum, slot, &intValue);84(void)outStream_writeByte(out, (jbyte)intValue);85break;86}8788case JDWP_TAG(CHAR): {89jint intValue;90error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)91(gdata->jvmti, thread, fnum, slot, &intValue);92(void)outStream_writeChar(out, (jchar)intValue);93break;94}9596case JDWP_TAG(FLOAT):97error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalFloat)98(gdata->jvmti, thread, fnum, slot, &value.f);99(void)outStream_writeFloat(out, value.f);100break;101102case JDWP_TAG(DOUBLE):103error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalDouble)104(gdata->jvmti, thread, fnum, slot, &value.d);105(void)outStream_writeDouble(out, value.d);106break;107108case JDWP_TAG(INT):109error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)110(gdata->jvmti, thread, fnum, slot, &value.i);111(void)outStream_writeInt(out, value.i);112break;113114case JDWP_TAG(LONG):115error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalLong)116(gdata->jvmti, thread, fnum, slot, &value.j);117(void)outStream_writeLong(out, value.j);118break;119120case JDWP_TAG(SHORT): {121jint intValue;122error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)123(gdata->jvmti, thread, fnum, slot, &intValue);124(void)outStream_writeShort(out, (jshort)intValue);125break;126}127128case JDWP_TAG(BOOLEAN):{129jint intValue;130error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalInt)131(gdata->jvmti, thread, fnum, slot, &intValue);132(void)outStream_writeBoolean(out, (jboolean)intValue);133break;134}135136default:137return JDWP_ERROR(INVALID_TAG);138}139}140141return map2jdwpError(error);142}143144static jdwpError145readVariableValue(JNIEnv *env, PacketInputStream *in, jthread thread,146FrameNumber fnum, jint slot, jbyte typeKey)147{148jvmtiError error;149jvalue value;150151if (isObjectTag(typeKey)) {152153value.l = inStream_readObjectRef(env, in);154155error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalObject)156(gdata->jvmti, thread, fnum, slot, value.l);157158} else {159switch (typeKey) {160case JDWP_TAG(BYTE):161value.b = inStream_readByte(in);162error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)163(gdata->jvmti, thread, fnum, slot, value.b);164break;165166case JDWP_TAG(CHAR):167value.c = inStream_readChar(in);168error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)169(gdata->jvmti, thread, fnum, slot, value.c);170break;171172case JDWP_TAG(FLOAT):173value.f = inStream_readFloat(in);174error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalFloat)175(gdata->jvmti, thread, fnum, slot, value.f);176break;177178case JDWP_TAG(DOUBLE):179value.d = inStream_readDouble(in);180error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalDouble)181(gdata->jvmti, thread, fnum, slot, value.d);182break;183184case JDWP_TAG(INT):185value.i = inStream_readInt(in);186error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)187(gdata->jvmti, thread, fnum, slot, value.i);188break;189190case JDWP_TAG(LONG):191value.j = inStream_readLong(in);192error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalLong)193(gdata->jvmti, thread, fnum, slot, value.j);194break;195196case JDWP_TAG(SHORT):197value.s = inStream_readShort(in);198error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)199(gdata->jvmti, thread, fnum, slot, value.s);200break;201202case JDWP_TAG(BOOLEAN):203value.z = inStream_readBoolean(in);204error = JVMTI_FUNC_PTR(gdata->jvmti,SetLocalInt)205(gdata->jvmti, thread, fnum, slot, value.z);206break;207208default:209return JDWP_ERROR(INVALID_TAG);210}211}212213return map2jdwpError(error);214}215216static jboolean217getValues(PacketInputStream *in, PacketOutputStream *out)218{219JNIEnv *env;220int i;221jdwpError serror;222jthread thread;223FrameID frame;224jint variableCount;225226env = getEnv();227228thread = inStream_readThreadRef(env, in);229if (inStream_error(in)) {230return JNI_TRUE;231}232frame = inStream_readFrameID(in);233if (inStream_error(in)) {234return JNI_TRUE;235}236variableCount = inStream_readInt(in);237if (inStream_error(in)) {238return JNI_TRUE;239}240241/*242* Validate the frame id243*/244serror = validateThreadFrame(thread, frame);245if (serror != JDWP_ERROR(NONE)) {246outStream_setError(out, serror);247return JNI_TRUE;248}249250(void)outStream_writeInt(out, variableCount);251for (i = 0; (i < variableCount) && !outStream_error(out); i++) {252jint slot;253jbyte typeKey;254FrameNumber fnum;255256slot = inStream_readInt(in);257if (inStream_error(in))258break;259typeKey = inStream_readByte(in);260if (inStream_error(in))261break;262263fnum = getFrameNumber(frame);264serror = writeVariableValue(env, out, thread, fnum, slot, typeKey);265if (serror != JDWP_ERROR(NONE)) {266outStream_setError(out, serror);267break;268}269}270271return JNI_TRUE;272}273274static jboolean275setValues(PacketInputStream *in, PacketOutputStream *out)276{277JNIEnv *env;278jint i;279jdwpError serror;280jthread thread;281FrameID frame;282jint variableCount;283284env = getEnv();285286thread = inStream_readThreadRef(env, in);287if (inStream_error(in)) {288return JNI_TRUE;289}290frame = inStream_readFrameID(in);291if (inStream_error(in)) {292return JNI_TRUE;293}294variableCount = inStream_readInt(in);295if (inStream_error(in)) {296return JNI_TRUE;297}298299/*300* Validate the frame id301*/302serror = validateThreadFrame(thread, frame);303if (serror != JDWP_ERROR(NONE)) {304outStream_setError(out, serror);305return JNI_TRUE;306}307308for (i = 0; (i < variableCount) && !inStream_error(in); i++) {309310jint slot;311jbyte typeKey;312FrameNumber fnum;313314slot = inStream_readInt(in);315if (inStream_error(in)) {316return JNI_TRUE;317}318typeKey = inStream_readByte(in);319if (inStream_error(in)) {320return JNI_TRUE;321}322323fnum = getFrameNumber(frame);324serror = readVariableValue(env, in, thread, fnum, slot, typeKey);325if (serror != JDWP_ERROR(NONE))326break;327}328329if (serror != JDWP_ERROR(NONE)) {330outStream_setError(out, serror);331}332333return JNI_TRUE;334}335336static jboolean337thisObject(PacketInputStream *in, PacketOutputStream *out)338{339JNIEnv *env;340jdwpError serror;341jthread thread;342FrameID frame;343344env = getEnv();345346thread = inStream_readThreadRef(env, in);347if (inStream_error(in)) {348return JNI_TRUE;349}350351frame = inStream_readFrameID(in);352if (inStream_error(in)) {353return JNI_TRUE;354}355356/*357* Validate the frame id358*/359serror = validateThreadFrame(thread, frame);360if (serror != JDWP_ERROR(NONE)) {361outStream_setError(out, serror);362return JNI_TRUE;363}364365WITH_LOCAL_REFS(env, 2) {366367jvmtiError error;368jmethodID method;369jlocation location;370FrameNumber fnum;371372/*373* Find out if the given frame is for a static or native method.374*/375fnum = getFrameNumber(frame);376error = JVMTI_FUNC_PTR(gdata->jvmti,GetFrameLocation)377(gdata->jvmti, thread, fnum, &method, &location);378if (error == JVMTI_ERROR_NONE) {379380jint modifiers;381382error = methodModifiers(method, &modifiers);383if (error == JVMTI_ERROR_NONE) {384385jobject this_object;386387/*388* Return null for static or native methods; otherwise, the JVM389* spec guarantees that "this" is in slot 0390*/391if (modifiers & (MOD_STATIC | MOD_NATIVE)) {392this_object = NULL;393(void)outStream_writeByte(out, specificTypeKey(env, this_object));394(void)outStream_writeObjectRef(env, out, this_object);395} else {396error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalObject)397(gdata->jvmti, thread, fnum, 0, &this_object);398if (error == JVMTI_ERROR_NONE) {399(void)outStream_writeByte(out, specificTypeKey(env, this_object));400(void)outStream_writeObjectRef(env, out, this_object);401}402}403404}405}406serror = map2jdwpError(error);407408} END_WITH_LOCAL_REFS(env);409410if (serror != JDWP_ERROR(NONE))411outStream_setError(out, serror);412413return JNI_TRUE;414}415416static jboolean417popFrames(PacketInputStream *in, PacketOutputStream *out)418{419jvmtiError error;420jdwpError serror;421jthread thread;422FrameID frame;423FrameNumber fnum;424425thread = inStream_readThreadRef(getEnv(), in);426if (inStream_error(in)) {427return JNI_TRUE;428}429430frame = inStream_readFrameID(in);431if (inStream_error(in)) {432return JNI_TRUE;433}434435/*436* Validate the frame id437*/438serror = validateThreadFrame(thread, frame);439if (serror != JDWP_ERROR(NONE)) {440outStream_setError(out, serror);441return JNI_TRUE;442}443444if (threadControl_isDebugThread(thread)) {445outStream_setError(out, JDWP_ERROR(INVALID_THREAD));446return JNI_TRUE;447}448449fnum = getFrameNumber(frame);450error = threadControl_popFrames(thread, fnum);451if (error != JVMTI_ERROR_NONE) {452serror = map2jdwpError(error);453outStream_setError(out, serror);454}455return JNI_TRUE;456}457458void *StackFrame_Cmds[] = { (void *)0x4459,(void *)getValues460,(void *)setValues461,(void *)thisObject462,(void *)popFrames463};464465466