20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "ci/ciInstance.hpp"
28 #include "ci/ciStreams.hpp"
29 #include "shark/sharkBuilder.hpp"
30 #include "shark/sharkConstant.hpp"
31 #include "shark/sharkValue.hpp"
32
33 using namespace llvm;
34
35 SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter) {
36 ciConstant constant = iter->get_constant();
37 ciType *type = NULL;
38 if (constant.basic_type() == T_OBJECT) {
39 ciEnv *env = ciEnv::current();
40 if (constant.as_object()->is_klass())
41 type = env->Class_klass();
42 else
43 type = env->String_klass();
44 }
45 return new SharkConstant(constant, type);
46 }
47
48 SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) {
49 bool will_link;
50 ciField *field = iter->get_field(will_link);
51 assert(will_link, "typeflow responsibility");
52
53 return new SharkConstant(field->constant_value(), field->type());
54 }
55
56 SharkConstant::SharkConstant(ciConstant constant, ciType *type) {
57 SharkValue *value = NULL;
58
59 switch (constant.basic_type()) {
60 case T_BOOLEAN:
61 case T_BYTE:
62 case T_CHAR:
63 case T_SHORT:
91 ShouldNotReachHere();
92 }
93
94 // Handle primitive types. We create SharkValues for these
95 // now; doing so doesn't emit any code, and it allows us to
96 // delegate a bunch of stuff to the SharkValue code.
97 if (value) {
98 _value = value;
99 _is_loaded = true;
100 _is_nonzero = value->zero_checked();
101 _is_two_word = value->is_two_word();
102 return;
103 }
104
105 // Handle reference types. This is tricky because some
106 // ciObjects are psuedo-objects that refer to oops which
107 // have yet to be created. We need to spot the unloaded
108 // objects (which differ between ldc* and get*, thanks!)
109 ciObject *object = constant.as_object();
110 assert(type != NULL, "shouldn't be");
111 if (object->is_klass()) {
112 // The constant returned for a klass is the ciKlass
113 // for the entry, but we want the java_mirror.
114 ciKlass *klass = object->as_klass();
115 if (!klass->is_loaded()) {
116 _is_loaded = false;
117 return;
118 }
119 object = klass->java_mirror();
120 }
121 if (object->is_null_object() || !object->can_be_constant()) {
122 _is_loaded = false;
123 return;
124 }
125
126 _value = NULL;
127 _object = object;
128 _type = type;
129 _is_loaded = true;
130 _is_nonzero = true;
131 _is_two_word = false;
132 }
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "ci/ciInstance.hpp"
28 #include "ci/ciStreams.hpp"
29 #include "shark/sharkBuilder.hpp"
30 #include "shark/sharkConstant.hpp"
31 #include "shark/sharkValue.hpp"
32
33 using namespace llvm;
34
35 SharkConstant* SharkConstant::for_ldc(ciBytecodeStream *iter) {
36 ciConstant constant = iter->get_constant();
37 ciType *type = NULL;
38 if (constant.basic_type() == T_OBJECT) {
39 ciEnv *env = ciEnv::current();
40 assert(constant.as_object()->klass() == env->String_klass() || constant.as_object()->klass() == env->Class_klass(), "should be");
41 type = constant.as_object()->klass();
42 }
43 return new SharkConstant(constant, type);
44 }
45
46 SharkConstant* SharkConstant::for_field(ciBytecodeStream *iter) {
47 bool will_link;
48 ciField *field = iter->get_field(will_link);
49 assert(will_link, "typeflow responsibility");
50
51 return new SharkConstant(field->constant_value(), field->type());
52 }
53
54 SharkConstant::SharkConstant(ciConstant constant, ciType *type) {
55 SharkValue *value = NULL;
56
57 switch (constant.basic_type()) {
58 case T_BOOLEAN:
59 case T_BYTE:
60 case T_CHAR:
61 case T_SHORT:
89 ShouldNotReachHere();
90 }
91
92 // Handle primitive types. We create SharkValues for these
93 // now; doing so doesn't emit any code, and it allows us to
94 // delegate a bunch of stuff to the SharkValue code.
95 if (value) {
96 _value = value;
97 _is_loaded = true;
98 _is_nonzero = value->zero_checked();
99 _is_two_word = value->is_two_word();
100 return;
101 }
102
103 // Handle reference types. This is tricky because some
104 // ciObjects are psuedo-objects that refer to oops which
105 // have yet to be created. We need to spot the unloaded
106 // objects (which differ between ldc* and get*, thanks!)
107 ciObject *object = constant.as_object();
108 assert(type != NULL, "shouldn't be");
109
110 if ((! object->is_null_object()) && object->klass() == ciEnv::current()->Class_klass()) {
111 ciKlass *klass = object->klass();
112 if (! klass->is_loaded()) {
113 _is_loaded = false;
114 return;
115 }
116 }
117
118 if (object->is_null_object() || ! object->can_be_constant() || ! object->is_loaded()) {
119 _is_loaded = false;
120 return;
121 }
122
123 _value = NULL;
124 _object = object;
125 _type = type;
126 _is_loaded = true;
127 _is_nonzero = true;
128 _is_two_word = false;
129 }
|