Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/back/MethodImpl.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 "MethodImpl.h"27#include "inStream.h"28#include "outStream.h"2930static jboolean31lineTable(PacketInputStream *in, PacketOutputStream *out)32{33jvmtiError error;34jint count = 0;35jvmtiLineNumberEntry *table = NULL;36jmethodID method;37jlocation firstCodeIndex;38jlocation lastCodeIndex;39jboolean isNative;4041/* JVMDI needed the class, but JVMTI does not so we ignore it */42(void)inStream_readClassRef(getEnv(), in);43if (inStream_error(in)) {44return JNI_TRUE;45}46method = inStream_readMethodID(in);47if (inStream_error(in)) {48return JNI_TRUE;49}5051/*52* JVMTI behavior for the calls below is unspecified for native53* methods, so we must check explicitly.54*/55isNative = isMethodNative(method);56if (isNative) {57outStream_setError(out, JDWP_ERROR(NATIVE_METHOD));58return JNI_TRUE;59}6061error = methodLocation(method, &firstCodeIndex, &lastCodeIndex);62if (error != JVMTI_ERROR_NONE) {63outStream_setError(out, map2jdwpError(error));64return JNI_TRUE;65}66(void)outStream_writeLocation(out, firstCodeIndex);67(void)outStream_writeLocation(out, lastCodeIndex);6869error = JVMTI_FUNC_PTR(gdata->jvmti,GetLineNumberTable)70(gdata->jvmti, method, &count, &table);71if (error == JVMTI_ERROR_ABSENT_INFORMATION) {72/*73* Indicate no line info with an empty table. The code indices74* are still useful, so we don't want to return an error75*/76(void)outStream_writeInt(out, 0);77} else if (error == JVMTI_ERROR_NONE) {78jint i;79(void)outStream_writeInt(out, count);80for (i = 0; (i < count) && !outStream_error(out); i++) {81(void)outStream_writeLocation(out, table[i].start_location);82(void)outStream_writeInt(out, table[i].line_number);83}84jvmtiDeallocate(table);85} else {86outStream_setError(out, map2jdwpError(error));87}88return JNI_TRUE;89}909192static jboolean93doVariableTable(PacketInputStream *in, PacketOutputStream *out,94int outputGenerics)95{96jvmtiError error;97jint count;98jvmtiLocalVariableEntry *table;99jmethodID method;100jint argsSize;101jboolean isNative;102103/* JVMDI needed the class, but JVMTI does not so we ignore it */104(void)inStream_readClassRef(getEnv(), in);105if (inStream_error(in)) {106return JNI_TRUE;107}108method = inStream_readMethodID(in);109if (inStream_error(in)) {110return JNI_TRUE;111}112113/*114* JVMTI behavior for the calls below is unspecified for native115* methods, so we must check explicitly.116*/117isNative = isMethodNative(method);118if (isNative) {119outStream_setError(out, JDWP_ERROR(NATIVE_METHOD));120return JNI_TRUE;121}122123error = JVMTI_FUNC_PTR(gdata->jvmti,GetArgumentsSize)124(gdata->jvmti, method, &argsSize);125if (error != JVMTI_ERROR_NONE) {126outStream_setError(out, map2jdwpError(error));127return JNI_TRUE;128}129130error = JVMTI_FUNC_PTR(gdata->jvmti,GetLocalVariableTable)131(gdata->jvmti, method, &count, &table);132if (error == JVMTI_ERROR_NONE) {133jint i;134(void)outStream_writeInt(out, argsSize);135(void)outStream_writeInt(out, count);136for (i = 0; (i < count) && !outStream_error(out); i++) {137jvmtiLocalVariableEntry *entry = &table[i];138(void)outStream_writeLocation(out, entry->start_location);139(void)outStream_writeString(out, entry->name);140(void)outStream_writeString(out, entry->signature);141if (outputGenerics == 1) {142writeGenericSignature(out, entry->generic_signature);143}144(void)outStream_writeInt(out, entry->length);145(void)outStream_writeInt(out, entry->slot);146147jvmtiDeallocate(entry->name);148jvmtiDeallocate(entry->signature);149if (entry->generic_signature != NULL) {150jvmtiDeallocate(entry->generic_signature);151}152}153154jvmtiDeallocate(table);155} else {156outStream_setError(out, map2jdwpError(error));157}158return JNI_TRUE;159}160161162static jboolean163variableTable(PacketInputStream *in, PacketOutputStream *out) {164return doVariableTable(in, out, 0);165}166167static jboolean168variableTableWithGenerics(PacketInputStream *in, PacketOutputStream *out) {169return doVariableTable(in, out, 1);170}171172173static jboolean174bytecodes(PacketInputStream *in, PacketOutputStream *out)175{176jvmtiError error;177unsigned char * bcp;178jint bytecodeCount;179jmethodID method;180181/* JVMDI needed the class, but JVMTI does not so we ignore it */182(void)inStream_readClassRef(getEnv(), in);183if (inStream_error(in)) {184return JNI_TRUE;185}186method = inStream_readMethodID(in);187if (inStream_error(in)) {188return JNI_TRUE;189}190191/* Initialize assuming no bytecodes and no error */192error = JVMTI_ERROR_NONE;193bytecodeCount = 0;194bcp = NULL;195196/* Only non-native methods have bytecodes, don't even ask if native. */197if ( !isMethodNative(method) ) {198error = JVMTI_FUNC_PTR(gdata->jvmti,GetBytecodes)199(gdata->jvmti, method, &bytecodeCount, &bcp);200}201if (error != JVMTI_ERROR_NONE) {202outStream_setError(out, map2jdwpError(error));203} else {204(void)outStream_writeByteArray(out, bytecodeCount, (jbyte *)bcp);205jvmtiDeallocate(bcp);206}207208return JNI_TRUE;209}210211static jboolean212isObsolete(PacketInputStream *in, PacketOutputStream *out)213{214jboolean isObsolete;215jmethodID method;216217/* JVMDI needed the class, but JVMTI does not so we ignore it */218(void)inStream_readClassRef(getEnv(), in);219if (inStream_error(in)) {220return JNI_TRUE;221}222method = inStream_readMethodID(in);223if (inStream_error(in)) {224return JNI_TRUE;225}226227isObsolete = isMethodObsolete(method);228(void)outStream_writeBoolean(out, isObsolete);229230return JNI_TRUE;231}232233void *Method_Cmds[] = { (void *)0x5234,(void *)lineTable235,(void *)variableTable236,(void *)bytecodes237,(void *)isObsolete238,(void *)variableTableWithGenerics239};240241242