jdk/src/share/back/ClassTypeImpl.c
changeset 2 90ce3da70b43
child 5506 202f599c92aa
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 #include "util.h"
       
    27 #include "ClassTypeImpl.h"
       
    28 #include "inStream.h"
       
    29 #include "outStream.h"
       
    30 
       
    31 static jboolean
       
    32 superclass(PacketInputStream *in, PacketOutputStream *out)
       
    33 {
       
    34     JNIEnv *env;
       
    35     jclass clazz;
       
    36 
       
    37     env = getEnv();
       
    38 
       
    39     clazz = inStream_readClassRef(env, in);
       
    40     if (inStream_error(in)) {
       
    41         return JNI_TRUE;
       
    42     }
       
    43 
       
    44     WITH_LOCAL_REFS(env, 1) {
       
    45 
       
    46         jclass superclass;
       
    47 
       
    48         superclass = JNI_FUNC_PTR(env,GetSuperclass)(env,clazz);
       
    49         (void)outStream_writeObjectRef(env, out, superclass);
       
    50 
       
    51     } END_WITH_LOCAL_REFS(env);
       
    52 
       
    53     return JNI_TRUE;
       
    54 }
       
    55 
       
    56 static jdwpError
       
    57 readStaticFieldValue(JNIEnv *env, PacketInputStream *in, jclass clazz,
       
    58                      jfieldID field, char *signature)
       
    59 {
       
    60     jvalue value;
       
    61     jdwpError serror = JDWP_ERROR(NONE);
       
    62 
       
    63     switch (signature[0]) {
       
    64         case JDWP_TAG(ARRAY):
       
    65         case JDWP_TAG(OBJECT):
       
    66             value.l = inStream_readObjectRef(env, in);
       
    67             JNI_FUNC_PTR(env,SetStaticObjectField)(env, clazz, field, value.l);
       
    68             break;
       
    69 
       
    70         case JDWP_TAG(BYTE):
       
    71             value.b = inStream_readByte(in);
       
    72             JNI_FUNC_PTR(env,SetStaticByteField)(env, clazz, field, value.b);
       
    73             break;
       
    74 
       
    75         case JDWP_TAG(CHAR):
       
    76             value.c = inStream_readChar(in);
       
    77             JNI_FUNC_PTR(env,SetStaticCharField)(env, clazz, field, value.c);
       
    78             break;
       
    79 
       
    80         case JDWP_TAG(FLOAT):
       
    81             value.f = inStream_readFloat(in);
       
    82             JNI_FUNC_PTR(env,SetStaticFloatField)(env, clazz, field, value.f);
       
    83             break;
       
    84 
       
    85         case JDWP_TAG(DOUBLE):
       
    86             value.d = inStream_readDouble(in);
       
    87             JNI_FUNC_PTR(env,SetStaticDoubleField)(env, clazz, field, value.d);
       
    88             break;
       
    89 
       
    90         case JDWP_TAG(INT):
       
    91             value.i = inStream_readInt(in);
       
    92             JNI_FUNC_PTR(env,SetStaticIntField)(env, clazz, field, value.i);
       
    93             break;
       
    94 
       
    95         case JDWP_TAG(LONG):
       
    96             value.j = inStream_readLong(in);
       
    97             JNI_FUNC_PTR(env,SetStaticLongField)(env, clazz, field, value.j);
       
    98             break;
       
    99 
       
   100         case JDWP_TAG(SHORT):
       
   101             value.s = inStream_readShort(in);
       
   102             JNI_FUNC_PTR(env,SetStaticShortField)(env, clazz, field, value.s);
       
   103             break;
       
   104 
       
   105         case JDWP_TAG(BOOLEAN):
       
   106             value.z = inStream_readBoolean(in);
       
   107             JNI_FUNC_PTR(env,SetStaticBooleanField)(env, clazz, field, value.z);
       
   108             break;
       
   109     }
       
   110 
       
   111     if (JNI_FUNC_PTR(env,ExceptionOccurred)(env)) {
       
   112         serror = JDWP_ERROR(INTERNAL);
       
   113     }
       
   114 
       
   115     return serror;
       
   116 }
       
   117 
       
   118 static jboolean
       
   119 setValues(PacketInputStream *in, PacketOutputStream *out)
       
   120 {
       
   121     JNIEnv *env;
       
   122     jint count;
       
   123     jclass clazz;
       
   124 
       
   125     env = getEnv();
       
   126 
       
   127     clazz = inStream_readClassRef(env, in);
       
   128     if (inStream_error(in)) {
       
   129         return JNI_TRUE;
       
   130     }
       
   131     count = inStream_readInt(in);
       
   132     if (inStream_error(in)) {
       
   133         return JNI_TRUE;
       
   134     }
       
   135 
       
   136     WITH_LOCAL_REFS(env, count) {
       
   137 
       
   138         int i;
       
   139 
       
   140         for (i = 0; i < count; i++) {
       
   141 
       
   142             jfieldID field;
       
   143             char *signature = NULL;
       
   144             jvmtiError error;
       
   145             jdwpError serror;
       
   146 
       
   147             field = inStream_readFieldID(in);
       
   148             if (inStream_error(in)) {
       
   149                 break;
       
   150             }
       
   151 
       
   152             error = fieldSignature(clazz, field, NULL, &signature, NULL);
       
   153             if (error != JVMTI_ERROR_NONE) {
       
   154                 break;
       
   155             }
       
   156 
       
   157             serror = readStaticFieldValue(env, in, clazz, field, signature);
       
   158 
       
   159             jvmtiDeallocate(signature);
       
   160 
       
   161             if ( serror != JDWP_ERROR(NONE) ) {
       
   162                 break;
       
   163             }
       
   164 
       
   165         }
       
   166 
       
   167     } END_WITH_LOCAL_REFS(env);
       
   168 
       
   169     return JNI_TRUE;
       
   170 }
       
   171 
       
   172 static jboolean
       
   173 invokeStatic(PacketInputStream *in, PacketOutputStream *out)
       
   174 {
       
   175     return sharedInvoke(in, out);
       
   176 }
       
   177 
       
   178 void *ClassType_Cmds[] = { (void *)0x4
       
   179     ,(void *)superclass
       
   180     ,(void *)setValues
       
   181     ,(void *)invokeStatic
       
   182     ,(void *)invokeStatic
       
   183 };