< prev index next >

src/share/vm/prims/jvmtiTagMap.cpp

Print this page




1040 
1041 // helper function to invoke string primitive value callback
1042 // returns visit control flags
1043 static jint invoke_string_value_callback(jvmtiStringPrimitiveValueCallback cb,
1044                                          CallbackWrapper* wrapper,
1045                                          oop str,
1046                                          void* user_data)
1047 {
1048   assert(str->klass() == SystemDictionary::String_klass(), "not a string");
1049 
1050   typeArrayOop s_value = java_lang_String::value(str);
1051 
1052   // JDK-6584008: the value field may be null if a String instance is
1053   // partially constructed.
1054   if (s_value == NULL) {
1055     return 0;
1056   }
1057   // get the string value and length
1058   // (string value may be offset from the base)
1059   int s_len = java_lang_String::length(str);
1060   int s_offset = java_lang_String::offset(str);
1061   jchar* value;
1062   if (s_len > 0) {
1063     value = s_value->char_at_addr(s_offset);

1064   } else {









1065     value = (jchar*) s_value->base(T_CHAR);
1066   }
1067 
1068   // invoke the callback
1069   return (*cb)(wrapper->klass_tag(),
1070                wrapper->obj_size(),
1071                wrapper->obj_tag_p(),
1072                value,
1073                (jint)s_len,
1074                user_data);





1075 }
1076 
1077 // helper function to invoke string primitive value callback
1078 // returns visit control flags
1079 static jint invoke_array_primitive_value_callback(jvmtiArrayPrimitiveValueCallback cb,
1080                                                   CallbackWrapper* wrapper,
1081                                                   oop obj,
1082                                                   void* user_data)
1083 {
1084   assert(obj->is_typeArray(), "not a primitive array");
1085 
1086   // get base address of first element
1087   typeArrayOop array = typeArrayOop(obj);
1088   BasicType type = TypeArrayKlass::cast(array->klass())->element_type();
1089   void* elements = array->base(type);
1090 
1091   // jvmtiPrimitiveType is defined so this mapping is always correct
1092   jvmtiPrimitiveType elem_type = (jvmtiPrimitiveType)type2char(type);
1093 
1094   return (*cb)(wrapper->klass_tag(),




1040 
1041 // helper function to invoke string primitive value callback
1042 // returns visit control flags
1043 static jint invoke_string_value_callback(jvmtiStringPrimitiveValueCallback cb,
1044                                          CallbackWrapper* wrapper,
1045                                          oop str,
1046                                          void* user_data)
1047 {
1048   assert(str->klass() == SystemDictionary::String_klass(), "not a string");
1049 
1050   typeArrayOop s_value = java_lang_String::value(str);
1051 
1052   // JDK-6584008: the value field may be null if a String instance is
1053   // partially constructed.
1054   if (s_value == NULL) {
1055     return 0;
1056   }
1057   // get the string value and length
1058   // (string value may be offset from the base)
1059   int s_len = java_lang_String::length(str);
1060   bool is_latin1 = java_lang_String::is_latin1(str);
1061   jchar* value;
1062   if (s_len > 0) {
1063     if (!is_latin1) {
1064       value = s_value->char_at_addr(0);
1065     } else {
1066       // Inflate latin1 encoded string to UTF16
1067       jchar* buf = NEW_C_HEAP_ARRAY(jchar, s_len, mtInternal);
1068       for (int i = 0; i < s_len; i++) {
1069         buf[i] = ((jchar) s_value->byte_at(i)) & 0xff;
1070       }
1071       value = &buf[0];
1072     }
1073   } else {
1074     // Don't use char_at_addr(0) if length is 0
1075     value = (jchar*) s_value->base(T_CHAR);
1076   }
1077 
1078   // invoke the callback
1079   jint res = (*cb)(wrapper->klass_tag(),
1080                    wrapper->obj_size(),
1081                    wrapper->obj_tag_p(),
1082                    value,
1083                    (jint)s_len,
1084                    user_data);
1085 
1086   if (is_latin1 && s_len > 0) {
1087     FREE_C_HEAP_ARRAY(jchar, value);
1088   }
1089   return res;
1090 }
1091 
1092 // helper function to invoke string primitive value callback
1093 // returns visit control flags
1094 static jint invoke_array_primitive_value_callback(jvmtiArrayPrimitiveValueCallback cb,
1095                                                   CallbackWrapper* wrapper,
1096                                                   oop obj,
1097                                                   void* user_data)
1098 {
1099   assert(obj->is_typeArray(), "not a primitive array");
1100 
1101   // get base address of first element
1102   typeArrayOop array = typeArrayOop(obj);
1103   BasicType type = TypeArrayKlass::cast(array->klass())->element_type();
1104   void* elements = array->base(type);
1105 
1106   // jvmtiPrimitiveType is defined so this mapping is always correct
1107   jvmtiPrimitiveType elem_type = (jvmtiPrimitiveType)type2char(type);
1108 
1109   return (*cb)(wrapper->klass_tag(),


< prev index next >