1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
// natField.cc - Implementation of java.lang.reflect.Field native methods.
/* Copyright (C) 1998, 1999 Cygnus Solutions
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <stdlib.h>
#include <cni.h>
#include <jvm.h>
#include <java/lang/reflect/Field.h>
#include <java/lang/reflect/Modifier.h>
#include <java/lang/IllegalArgumentException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/Byte.h>
#include <java/lang/Short.h>
#include <java/lang/Integer.h>
#include <java/lang/Long.h>
#include <java/lang/Float.h>
#include <java/lang/Double.h>
#include <java/lang/Boolean.h>
#include <java/lang/Character.h>
#include <java-field.h>
jint
java::lang::reflect::Field::getModifiers ()
{
return _Jv_FromReflectedField (this)->getModifiers ();
}
jstring
java::lang::reflect::Field::getName ()
{
if (name == NULL)
name = _Jv_NewStringUtf8Const (_Jv_FromReflectedField (this)->name);
return name;
}
jclass
java::lang::reflect::Field::getType ()
{
jfieldID fld = _Jv_FromReflectedField (this);
if (! fld->isResolved())
{
JvSynchronize sync (declaringClass);
if (! fld->isResolved())
{
fld->type
= _Jv_FindClassFromSignature(((Utf8Const*) (fld->type))->data,
declaringClass->getClassLoader());
fld->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
}
}
return fld->type;
}
static void
_Jv_CheckFieldAccessibility (jfieldID /*fld*/, jclass /*caller*/)
{
#if 0
if (caller == NULL)
caller = getCaller();
#endif
#if 0
_Jv_ushort flags = fld->getModifiers();
check accesss;
#endif
}
static void*
getAddr (java::lang::reflect::Field* field, jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (field);
_Jv_ushort flags = fld->getModifiers();
if (! (flags & java::lang::reflect::Modifier::PUBLIC)
&& ! field->isAccessible ())
_Jv_CheckFieldAccessibility (fld, caller);
if (flags & java::lang::reflect::Modifier::STATIC)
{
jclass fldClass = field->getDeclaringClass ();
JvInitClass(fldClass);
return fld->u.addr;
}
else
{
if (obj == NULL)
_Jv_Throw (new java::lang::NullPointerException ());
if (! _Jv_IsInstanceOf (obj, field->getDeclaringClass()))
JvThrow (new java::lang::IllegalArgumentException ());
return (void*) ((char*) obj + fld->getOffset ());
}
}
static jboolean
getBoolean (jclass cls, void* addr)
{
if (cls == JvPrimClass (boolean))
return * (jboolean *) addr;
_Jv_Throw (new java::lang::IllegalArgumentException());
}
static jchar
getChar (jclass cls, void* addr)
{
if (cls == JvPrimClass (char))
return * (jchar *) addr;
_Jv_Throw (new java::lang::IllegalArgumentException());
}
static jbyte
getByte (jclass cls, void* addr)
{
if (cls == JvPrimClass (byte))
return * (jbyte *) addr;
_Jv_Throw (new java::lang::IllegalArgumentException());
}
static jshort
getShort (jclass cls, void* addr)
{
if (cls == JvPrimClass (short))
return * (jshort *) addr;
if (cls == JvPrimClass (byte))
return * (jbyte *) addr;
_Jv_Throw (new java::lang::IllegalArgumentException());
}
static jint
getInt (jclass cls, void* addr)
{
if (cls == JvPrimClass (int))
return * (jint *) addr;
if (cls == JvPrimClass (short))
return * (jshort *) addr;
if (cls == JvPrimClass (char))
return * (jchar *) addr;
if (cls == JvPrimClass (byte))
return * (jbyte *) addr;
_Jv_Throw (new java::lang::IllegalArgumentException());
}
static jlong
getLong (jclass cls, void* addr)
{
if (cls == JvPrimClass (long))
return * (jlong *) addr;
return ::getInt(cls, addr);
}
static jfloat
getFloat (jclass cls, void* addr)
{
if (cls == JvPrimClass (float))
return * (jfloat *) addr;
if (cls == JvPrimClass (long))
return * (jlong *) addr;
return ::getInt(cls, addr);
}
static jdouble
getDouble (jclass cls, void* addr)
{
if (cls == JvPrimClass (double))
return * (jdouble *) addr;
if (cls == JvPrimClass (float))
return * (jfloat *) addr;
if (cls == JvPrimClass (long))
return * (jlong *) addr;
return ::getInt(cls, addr);
}
jboolean
java::lang::reflect::Field::getBoolean (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getBoolean (fld->type, getAddr (this, caller, obj));
}
jchar
java::lang::reflect::Field::getChar (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getChar (fld->type, getAddr (this, caller, obj));
}
jbyte
java::lang::reflect::Field::getByte (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getByte (fld->type, getAddr (this, caller, obj));
}
jshort
java::lang::reflect::Field::getShort (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getShort (fld->type, getAddr (this, caller, obj));
}
jint
java::lang::reflect::Field::getInt (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getInt (fld->type, getAddr (this, caller, obj));
}
jlong
java::lang::reflect::Field::getLong (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getLong (fld->type, getAddr (this, caller, obj));
}
jfloat
java::lang::reflect::Field::getFloat (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getFloat (fld->type, getAddr (this, caller, obj));
}
jdouble
java::lang::reflect::Field::getDouble (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
return ::getDouble (fld->type, getAddr (this, caller, obj));
}
jobject
java::lang::reflect::Field::get (jclass caller, jobject obj)
{
jfieldID fld = _Jv_FromReflectedField (this);
void* addr = getAddr (this, caller, obj);
if (! fld->type->isPrimitive ())
return * (jobject*) addr;
if (fld->type == JvPrimClass (double))
return new java::lang::Double (* (jdouble*) addr);
if (fld->type == JvPrimClass (float))
return new java::lang::Float (* (jfloat*) addr);
if (fld->type == JvPrimClass (long))
return new java::lang::Long (* (jlong*) addr);
if (fld->type == JvPrimClass (int))
return new java::lang::Integer (* (jint*) addr);
if (fld->type == JvPrimClass (short))
return new java::lang::Short (* (jshort*) addr);
if (fld->type == JvPrimClass (byte))
return new java::lang::Byte (* (jbyte*) addr);
if (fld->type == JvPrimClass (char))
return new java::lang::Character (* (jchar*) addr);
if (fld->type == JvPrimClass (boolean))
if (* (jboolean*) addr)
return java::lang::Boolean::TRUE;
else
return java::lang::Boolean::FALSE;
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setBoolean (jclass type, void *addr, jboolean value)
{
if (type == JvPrimClass (boolean))
* (jboolean *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setChar (jclass type, void *addr, jchar value)
{
if (type == JvPrimClass (char))
* (jchar *) addr = value;
else if (type == JvPrimClass (int))
* (jint *) addr = value;
else if (type == JvPrimClass (long))
* (jlong *) addr = value;
else if (type == JvPrimClass (float))
* (jfloat *) addr = value;
else if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setByte (jclass type, void *addr, jbyte value)
{
if (type == JvPrimClass (byte))
* (jbyte *) addr = value;
else if (type == JvPrimClass (short))
* (jshort *) addr = value;
else if (type == JvPrimClass (int))
* (jint *) addr = value;
else if (type == JvPrimClass (long))
* (jlong *) addr = value;
else if (type == JvPrimClass (float))
* (jfloat *) addr = value;
else if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setShort (jclass type, void *addr, jshort value)
{
if (type == JvPrimClass (short))
* (jshort *) addr = value;
else if (type == JvPrimClass (int))
* (jint *) addr = value;
else if (type == JvPrimClass (long))
* (jlong *) addr = value;
else if (type == JvPrimClass (float))
* (jfloat *) addr = value;
else if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setInt (jclass type, void *addr, jint value)
{
if (type == JvPrimClass (int))
* (jint *) addr = value;
else if (type == JvPrimClass (long))
* (jlong *) addr = value;
else if (type == JvPrimClass (float))
* (jfloat *) addr = value;
else if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setLong (jclass type, void *addr, jlong value)
{
if (type == JvPrimClass (long))
* (jlong *) addr = value;
else if (type == JvPrimClass (float))
* (jfloat *) addr = value;
else if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setFloat (jclass type, void *addr, jfloat value)
{
if (type == JvPrimClass (float))
* (jfloat *) addr = value;
else if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
static void
setDouble (jclass type, void *addr, jdouble value)
{
if (type == JvPrimClass (double))
* (jdouble *) addr = value;
else
JvThrow (new java::lang::IllegalArgumentException());
}
void
java::lang::reflect::Field::setBoolean (jclass caller, jobject obj, jboolean b)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setBoolean (fld->type, getAddr (this, caller, obj), b);
}
void
java::lang::reflect::Field::setChar (jclass caller, jobject obj, jchar c)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setChar (fld->type, getAddr (this, caller, obj), c);
}
void
java::lang::reflect::Field::setByte (jclass caller, jobject obj, jbyte b)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setByte (fld->type, getAddr (this, caller, obj), b);
}
void
java::lang::reflect::Field::setShort (jclass caller, jobject obj, jshort s)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setShort (fld->type, getAddr (this, caller, obj), s);
}
void
java::lang::reflect::Field::setInt (jclass caller, jobject obj, jint i)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setInt (fld->type, getAddr (this, caller, obj), i);
}
void
java::lang::reflect::Field::setLong (jclass caller, jobject obj, jlong l)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setLong (fld->type, getAddr (this, caller, obj), l);
}
void
java::lang::reflect::Field::setFloat (jclass caller, jobject obj, jfloat f)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setFloat (fld->type, getAddr (this, caller, obj), f);
}
void
java::lang::reflect::Field::setDouble (jclass caller, jobject obj, jdouble d)
{
jfieldID fld = _Jv_FromReflectedField (this);
::setDouble (fld->type, getAddr (this, caller, obj), d);
}
void
java::lang::reflect::Field::set (jclass caller, jobject object, jobject value, jclass type)
{
if (! _Jv_IsInstanceOf (value, type))
JvThrow (new java::lang::IllegalArgumentException ());
void* addr = getAddr (this, caller, object);
* (jobject*) addr = value;
}
|