comparison src/share/vm/prims/jvm.cpp @ 13086:096c224171c4

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 20 Nov 2013 00:10:38 +0100
parents cefad50507d8 615d83933195
children d8041d695d19
comparison
equal deleted inserted replaced
12782:92b7ec34ddfa 13086:096c224171c4
668 668
669 669
670 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth)) 670 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env, int depth))
671 JVMWrapper("JVM_GetCallerClass"); 671 JVMWrapper("JVM_GetCallerClass");
672 672
673 // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation. 673 // Pre-JDK 8 and early builds of JDK 8 don't have a CallerSensitive annotation; or
674 if (!JDK_Version::is_gte_jdk18x_version() || SystemDictionary::reflect_CallerSensitive_klass() == NULL) { 674 // sun.reflect.Reflection.getCallerClass with a depth parameter is provided
675 // temporarily for existing code to use until a replacement API is defined.
676 if (SystemDictionary::reflect_CallerSensitive_klass() == NULL || depth != JVM_CALLER_DEPTH) {
675 Klass* k = thread->security_get_caller_class(depth); 677 Klass* k = thread->security_get_caller_class(depth);
676 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror()); 678 return (k == NULL) ? NULL : (jclass) JNIHandles::make_local(env, k->java_mirror());
677 } else {
678 // Basic handshaking with Java_sun_reflect_Reflection_getCallerClass
679 assert(depth == -1, "wrong handshake depth");
680 } 679 }
681 680
682 // Getting the class of the caller frame. 681 // Getting the class of the caller frame.
683 // 682 //
684 // The call stack at this point looks something like this: 683 // The call stack at this point looks something like this:
3965 "initialization failed" 3964 "initialization failed"
3966 ); 3965 );
3967 } 3966 }
3968 3967
3969 3968
3970 // Serialization
3971 JVM_ENTRY(void, JVM_SetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj,
3972 jlongArray fieldIDs, jcharArray typecodes, jbyteArray data))
3973 assert(!JDK_Version::is_gte_jdk14x_version(), "should only be used in 1.3.1 and earlier");
3974
3975 typeArrayOop tcodes = typeArrayOop(JNIHandles::resolve(typecodes));
3976 typeArrayOop dbuf = typeArrayOop(JNIHandles::resolve(data));
3977 typeArrayOop fids = typeArrayOop(JNIHandles::resolve(fieldIDs));
3978 oop o = JNIHandles::resolve(obj);
3979
3980 if (o == NULL || fids == NULL || dbuf == NULL || tcodes == NULL) {
3981 THROW(vmSymbols::java_lang_NullPointerException());
3982 }
3983
3984 jsize nfids = fids->length();
3985 if (nfids == 0) return;
3986
3987 if (tcodes->length() < nfids) {
3988 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
3989 }
3990
3991 jsize off = 0;
3992 /* loop through fields, setting values */
3993 for (jsize i = 0; i < nfids; i++) {
3994 jfieldID fid = (jfieldID)(intptr_t) fids->long_at(i);
3995 int field_offset;
3996 if (fid != NULL) {
3997 // NULL is a legal value for fid, but retrieving the field offset
3998 // trigger assertion in that case
3999 field_offset = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
4000 }
4001
4002 switch (tcodes->char_at(i)) {
4003 case 'Z':
4004 if (fid != NULL) {
4005 jboolean val = (dbuf->byte_at(off) != 0) ? JNI_TRUE : JNI_FALSE;
4006 o->bool_field_put(field_offset, val);
4007 }
4008 off++;
4009 break;
4010
4011 case 'B':
4012 if (fid != NULL) {
4013 o->byte_field_put(field_offset, dbuf->byte_at(off));
4014 }
4015 off++;
4016 break;
4017
4018 case 'C':
4019 if (fid != NULL) {
4020 jchar val = ((dbuf->byte_at(off + 0) & 0xFF) << 8)
4021 + ((dbuf->byte_at(off + 1) & 0xFF) << 0);
4022 o->char_field_put(field_offset, val);
4023 }
4024 off += 2;
4025 break;
4026
4027 case 'S':
4028 if (fid != NULL) {
4029 jshort val = ((dbuf->byte_at(off + 0) & 0xFF) << 8)
4030 + ((dbuf->byte_at(off + 1) & 0xFF) << 0);
4031 o->short_field_put(field_offset, val);
4032 }
4033 off += 2;
4034 break;
4035
4036 case 'I':
4037 if (fid != NULL) {
4038 jint ival = ((dbuf->byte_at(off + 0) & 0xFF) << 24)
4039 + ((dbuf->byte_at(off + 1) & 0xFF) << 16)
4040 + ((dbuf->byte_at(off + 2) & 0xFF) << 8)
4041 + ((dbuf->byte_at(off + 3) & 0xFF) << 0);
4042 o->int_field_put(field_offset, ival);
4043 }
4044 off += 4;
4045 break;
4046
4047 case 'F':
4048 if (fid != NULL) {
4049 jint ival = ((dbuf->byte_at(off + 0) & 0xFF) << 24)
4050 + ((dbuf->byte_at(off + 1) & 0xFF) << 16)
4051 + ((dbuf->byte_at(off + 2) & 0xFF) << 8)
4052 + ((dbuf->byte_at(off + 3) & 0xFF) << 0);
4053 jfloat fval = (*int_bits_to_float_fn)(env, NULL, ival);
4054 o->float_field_put(field_offset, fval);
4055 }
4056 off += 4;
4057 break;
4058
4059 case 'J':
4060 if (fid != NULL) {
4061 jlong lval = (((jlong) dbuf->byte_at(off + 0) & 0xFF) << 56)
4062 + (((jlong) dbuf->byte_at(off + 1) & 0xFF) << 48)
4063 + (((jlong) dbuf->byte_at(off + 2) & 0xFF) << 40)
4064 + (((jlong) dbuf->byte_at(off + 3) & 0xFF) << 32)
4065 + (((jlong) dbuf->byte_at(off + 4) & 0xFF) << 24)
4066 + (((jlong) dbuf->byte_at(off + 5) & 0xFF) << 16)
4067 + (((jlong) dbuf->byte_at(off + 6) & 0xFF) << 8)
4068 + (((jlong) dbuf->byte_at(off + 7) & 0xFF) << 0);
4069 o->long_field_put(field_offset, lval);
4070 }
4071 off += 8;
4072 break;
4073
4074 case 'D':
4075 if (fid != NULL) {
4076 jlong lval = (((jlong) dbuf->byte_at(off + 0) & 0xFF) << 56)
4077 + (((jlong) dbuf->byte_at(off + 1) & 0xFF) << 48)
4078 + (((jlong) dbuf->byte_at(off + 2) & 0xFF) << 40)
4079 + (((jlong) dbuf->byte_at(off + 3) & 0xFF) << 32)
4080 + (((jlong) dbuf->byte_at(off + 4) & 0xFF) << 24)
4081 + (((jlong) dbuf->byte_at(off + 5) & 0xFF) << 16)
4082 + (((jlong) dbuf->byte_at(off + 6) & 0xFF) << 8)
4083 + (((jlong) dbuf->byte_at(off + 7) & 0xFF) << 0);
4084 jdouble dval = (*long_bits_to_double_fn)(env, NULL, lval);
4085 o->double_field_put(field_offset, dval);
4086 }
4087 off += 8;
4088 break;
4089
4090 default:
4091 // Illegal typecode
4092 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "illegal typecode");
4093 }
4094 }
4095 JVM_END
4096
4097
4098 JVM_ENTRY(void, JVM_GetPrimitiveFieldValues(JNIEnv *env, jclass cb, jobject obj,
4099 jlongArray fieldIDs, jcharArray typecodes, jbyteArray data))
4100 assert(!JDK_Version::is_gte_jdk14x_version(), "should only be used in 1.3.1 and earlier");
4101
4102 typeArrayOop tcodes = typeArrayOop(JNIHandles::resolve(typecodes));
4103 typeArrayOop dbuf = typeArrayOop(JNIHandles::resolve(data));
4104 typeArrayOop fids = typeArrayOop(JNIHandles::resolve(fieldIDs));
4105 oop o = JNIHandles::resolve(obj);
4106
4107 if (o == NULL || fids == NULL || dbuf == NULL || tcodes == NULL) {
4108 THROW(vmSymbols::java_lang_NullPointerException());
4109 }
4110
4111 jsize nfids = fids->length();
4112 if (nfids == 0) return;
4113
4114 if (tcodes->length() < nfids) {
4115 THROW(vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
4116 }
4117
4118 /* loop through fields, fetching values */
4119 jsize off = 0;
4120 for (jsize i = 0; i < nfids; i++) {
4121 jfieldID fid = (jfieldID)(intptr_t) fids->long_at(i);
4122 if (fid == NULL) {
4123 THROW(vmSymbols::java_lang_NullPointerException());
4124 }
4125 int field_offset = jfieldIDWorkaround::from_instance_jfieldID(o->klass(), fid);
4126
4127 switch (tcodes->char_at(i)) {
4128 case 'Z':
4129 {
4130 jboolean val = o->bool_field(field_offset);
4131 dbuf->byte_at_put(off++, (val != 0) ? 1 : 0);
4132 }
4133 break;
4134
4135 case 'B':
4136 dbuf->byte_at_put(off++, o->byte_field(field_offset));
4137 break;
4138
4139 case 'C':
4140 {
4141 jchar val = o->char_field(field_offset);
4142 dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
4143 dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
4144 }
4145 break;
4146
4147 case 'S':
4148 {
4149 jshort val = o->short_field(field_offset);
4150 dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
4151 dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
4152 }
4153 break;
4154
4155 case 'I':
4156 {
4157 jint val = o->int_field(field_offset);
4158 dbuf->byte_at_put(off++, (val >> 24) & 0xFF);
4159 dbuf->byte_at_put(off++, (val >> 16) & 0xFF);
4160 dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
4161 dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
4162 }
4163 break;
4164
4165 case 'F':
4166 {
4167 jfloat fval = o->float_field(field_offset);
4168 jint ival = (*float_to_int_bits_fn)(env, NULL, fval);
4169 dbuf->byte_at_put(off++, (ival >> 24) & 0xFF);
4170 dbuf->byte_at_put(off++, (ival >> 16) & 0xFF);
4171 dbuf->byte_at_put(off++, (ival >> 8) & 0xFF);
4172 dbuf->byte_at_put(off++, (ival >> 0) & 0xFF);
4173 }
4174 break;
4175
4176 case 'J':
4177 {
4178 jlong val = o->long_field(field_offset);
4179 dbuf->byte_at_put(off++, (val >> 56) & 0xFF);
4180 dbuf->byte_at_put(off++, (val >> 48) & 0xFF);
4181 dbuf->byte_at_put(off++, (val >> 40) & 0xFF);
4182 dbuf->byte_at_put(off++, (val >> 32) & 0xFF);
4183 dbuf->byte_at_put(off++, (val >> 24) & 0xFF);
4184 dbuf->byte_at_put(off++, (val >> 16) & 0xFF);
4185 dbuf->byte_at_put(off++, (val >> 8) & 0xFF);
4186 dbuf->byte_at_put(off++, (val >> 0) & 0xFF);
4187 }
4188 break;
4189
4190 case 'D':
4191 {
4192 jdouble dval = o->double_field(field_offset);
4193 jlong lval = (*double_to_long_bits_fn)(env, NULL, dval);
4194 dbuf->byte_at_put(off++, (lval >> 56) & 0xFF);
4195 dbuf->byte_at_put(off++, (lval >> 48) & 0xFF);
4196 dbuf->byte_at_put(off++, (lval >> 40) & 0xFF);
4197 dbuf->byte_at_put(off++, (lval >> 32) & 0xFF);
4198 dbuf->byte_at_put(off++, (lval >> 24) & 0xFF);
4199 dbuf->byte_at_put(off++, (lval >> 16) & 0xFF);
4200 dbuf->byte_at_put(off++, (lval >> 8) & 0xFF);
4201 dbuf->byte_at_put(off++, (lval >> 0) & 0xFF);
4202 }
4203 break;
4204
4205 default:
4206 // Illegal typecode
4207 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "illegal typecode");
4208 }
4209 }
4210 JVM_END
4211
4212 3969
4213 // Shared JNI/JVM entry points ////////////////////////////////////////////////////////////// 3970 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
4214 3971
4215 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, Handle loader, Handle protection_domain, jboolean throwError, TRAPS) { 3972 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init, Handle loader, Handle protection_domain, jboolean throwError, TRAPS) {
4216 // Security Note: 3973 // Security Note: