153 case Bytecodes::_fconst_2:
154 push(SharkValue::jfloat_constant(2));
155 break;
156
157 case Bytecodes::_dconst_0:
158 push(SharkValue::jdouble_constant(0));
159 break;
160 case Bytecodes::_dconst_1:
161 push(SharkValue::jdouble_constant(1));
162 break;
163
164 case Bytecodes::_bipush:
165 push(SharkValue::jint_constant(iter()->get_constant_u1()));
166 break;
167 case Bytecodes::_sipush:
168 push(SharkValue::jint_constant(iter()->get_constant_u2()));
169 break;
170
171 case Bytecodes::_ldc:
172 case Bytecodes::_ldc_w:
173 case Bytecodes::_ldc2_w:
174 push(SharkConstant::for_ldc(iter())->value(builder()));
175 break;
176
177 case Bytecodes::_iload_0:
178 case Bytecodes::_lload_0:
179 case Bytecodes::_fload_0:
180 case Bytecodes::_dload_0:
181 case Bytecodes::_aload_0:
182 push(local(0));
183 break;
184 case Bytecodes::_iload_1:
185 case Bytecodes::_lload_1:
186 case Bytecodes::_fload_1:
187 case Bytecodes::_dload_1:
188 case Bytecodes::_aload_1:
189 push(local(1));
190 break;
191 case Bytecodes::_iload_2:
192 case Bytecodes::_lload_2:
193 case Bytecodes::_fload_2:
194 case Bytecodes::_dload_2:
195 case Bytecodes::_aload_2:
196 push(local(2));
983 special_result = LLVMValue::jlong_constant(0);
984 else
985 special_result = LLVMValue::jint_constant(0);
986 }
987 else {
988 special_result = a;
989 }
990 builder()->CreateBr(done);
991
992 builder()->SetInsertPoint(general_case);
993 Value *general_result;
994 if (is_rem)
995 general_result = builder()->CreateSRem(a, b);
996 else
997 general_result = builder()->CreateSDiv(a, b);
998 builder()->CreateBr(done);
999
1000 builder()->SetInsertPoint(done);
1001 PHINode *result;
1002 if (is_long)
1003 result = builder()->CreatePHI(SharkType::jlong_type(), "result");
1004 else
1005 result = builder()->CreatePHI(SharkType::jint_type(), "result");
1006 result->addIncoming(special_result, special_case);
1007 result->addIncoming(general_result, general_case);
1008
1009 if (is_long)
1010 push(SharkValue::create_jlong(result, false));
1011 else
1012 push(SharkValue::create_jint(result, false));
1013 }
1014
1015 void SharkBlock::do_field_access(bool is_get, bool is_field) {
1016 bool will_link;
1017 ciField *field = iter()->get_field(will_link);
1018 assert(will_link, "typeflow responsibility");
1019 assert(is_field != field->is_static(), "mismatch");
1020
1021 // Pop the value off the stack where necessary
1022 SharkValue *value = NULL;
1023 if (!is_get)
1024 value = pop();
1025
1026 // Find the object we're accessing, if necessary
1027 Value *object = NULL;
1028 if (is_field) {
1029 SharkValue *value = pop();
1030 check_null(value);
1031 object = value->generic_value();
1032 }
1033 if (is_get && field->is_constant()) {
1034 SharkConstant *constant = SharkConstant::for_field(iter());
1035 if (constant->is_loaded())
1036 value = constant->value(builder());
1037 }
1038 if (!is_get || value == NULL) {
1039 if (!is_field)
1040 object = builder()->CreateInlineOop(field->holder());
1041
1042 BasicType basic_type = field->type()->basic_type();
1043 const Type *stack_type = SharkType::to_stackType(basic_type);
1044 const Type *field_type = SharkType::to_arrayType(basic_type);
1045
1046 Value *addr = builder()->CreateAddressOfStructEntry(
1047 object, in_ByteSize(field->offset_in_bytes()),
1048 PointerType::getUnqual(field_type),
1049 "addr");
1050
1051 // Do the access
1052 if (is_get) {
1053 Value *field_value = builder()->CreateLoad(addr);
1054
1055 if (field_type != stack_type) {
1056 field_value = builder()->CreateIntCast(
1057 field_value, stack_type, basic_type != T_CHAR);
1058 }
1059
1060 value = SharkValue::create_generic(field->type(), field_value, false);
1061 }
1062 else {
1063 Value *field_value = value->generic_value();
1064
1065 if (field_type != stack_type) {
1066 field_value = builder()->CreateIntCast(
1067 field_value, field_type, basic_type != T_CHAR);
1068 }
1069
1070 builder()->CreateStore(field_value, addr);
1071
1072 if (!field->type()->is_primitive_type())
1073 builder()->CreateUpdateBarrierSet(oopDesc::bs(), addr);
1074
1075 if (field->is_volatile())
1076 builder()->CreateMemoryBarrier(SharkBuilder::BARRIER_STORELOAD);
1077 }
1078 }
1079
1080 // Push the value onto the stack where necessary
1081 if (is_get)
1082 push(value);
1083 }
1084
1085 void SharkBlock::do_lcmp() {
1086 Value *b = pop()->jlong_value();
1087 Value *a = pop()->jlong_value();
1088
1089 BasicBlock *ip = builder()->GetBlockInsertionPoint();
1090 BasicBlock *ne = builder()->CreateBlock(ip, "lcmp_ne");
1091 BasicBlock *lt = builder()->CreateBlock(ip, "lcmp_lt");
1092 BasicBlock *gt = builder()->CreateBlock(ip, "lcmp_gt");
1093 BasicBlock *done = builder()->CreateBlock(ip, "done");
1094
1095 BasicBlock *eq = builder()->GetInsertBlock();
1096 builder()->CreateCondBr(builder()->CreateICmpEQ(a, b), done, ne);
1097
1098 builder()->SetInsertPoint(ne);
1099 builder()->CreateCondBr(builder()->CreateICmpSLT(a, b), lt, gt);
1100
1101 builder()->SetInsertPoint(lt);
1102 builder()->CreateBr(done);
1103
1104 builder()->SetInsertPoint(gt);
1105 builder()->CreateBr(done);
1106
1107 builder()->SetInsertPoint(done);
1108 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), "result");
1109 result->addIncoming(LLVMValue::jint_constant(-1), lt);
1110 result->addIncoming(LLVMValue::jint_constant(0), eq);
1111 result->addIncoming(LLVMValue::jint_constant(1), gt);
1112
1113 push(SharkValue::create_jint(result, false));
1114 }
1115
1116 void SharkBlock::do_fcmp(bool is_double, bool unordered_is_greater) {
1117 Value *a, *b;
1118 if (is_double) {
1119 b = pop()->jdouble_value();
1120 a = pop()->jdouble_value();
1121 }
1122 else {
1123 b = pop()->jfloat_value();
1124 a = pop()->jfloat_value();
1125 }
1126
1127 BasicBlock *ip = builder()->GetBlockInsertionPoint();
1128 BasicBlock *ordered = builder()->CreateBlock(ip, "ordered");
1135 builder()->CreateCondBr(
1136 builder()->CreateFCmpUNO(a, b),
1137 unordered_is_greater ? gt : lt, ordered);
1138
1139 builder()->SetInsertPoint(ordered);
1140 builder()->CreateCondBr(builder()->CreateFCmpULT(a, b), lt, ge);
1141
1142 builder()->SetInsertPoint(ge);
1143 builder()->CreateCondBr(builder()->CreateFCmpUGT(a, b), gt, eq);
1144
1145 builder()->SetInsertPoint(lt);
1146 builder()->CreateBr(done);
1147
1148 builder()->SetInsertPoint(gt);
1149 builder()->CreateBr(done);
1150
1151 builder()->SetInsertPoint(eq);
1152 builder()->CreateBr(done);
1153
1154 builder()->SetInsertPoint(done);
1155 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), "result");
1156 result->addIncoming(LLVMValue::jint_constant(-1), lt);
1157 result->addIncoming(LLVMValue::jint_constant(0), eq);
1158 result->addIncoming(LLVMValue::jint_constant(1), gt);
1159
1160 push(SharkValue::create_jint(result, false));
1161 }
1162
1163 void SharkBlock::emit_IR() {
1164 ShouldNotCallThis();
1165 }
1166
1167 SharkState* SharkBlock::entry_state() {
1168 ShouldNotCallThis();
1169 }
1170
1171 void SharkBlock::do_zero_check(SharkValue* value) {
1172 ShouldNotCallThis();
1173 }
1174
1175 void SharkBlock::maybe_add_backedge_safepoint() {
|
153 case Bytecodes::_fconst_2:
154 push(SharkValue::jfloat_constant(2));
155 break;
156
157 case Bytecodes::_dconst_0:
158 push(SharkValue::jdouble_constant(0));
159 break;
160 case Bytecodes::_dconst_1:
161 push(SharkValue::jdouble_constant(1));
162 break;
163
164 case Bytecodes::_bipush:
165 push(SharkValue::jint_constant(iter()->get_constant_u1()));
166 break;
167 case Bytecodes::_sipush:
168 push(SharkValue::jint_constant(iter()->get_constant_u2()));
169 break;
170
171 case Bytecodes::_ldc:
172 case Bytecodes::_ldc_w:
173 case Bytecodes::_ldc2_w: {
174 SharkConstant* constant = SharkConstant::for_ldc(iter());
175 assert(constant->is_loaded(), "trap should handle unloaded classes");
176 push(constant->value(builder()));
177 break;
178 }
179 case Bytecodes::_iload_0:
180 case Bytecodes::_lload_0:
181 case Bytecodes::_fload_0:
182 case Bytecodes::_dload_0:
183 case Bytecodes::_aload_0:
184 push(local(0));
185 break;
186 case Bytecodes::_iload_1:
187 case Bytecodes::_lload_1:
188 case Bytecodes::_fload_1:
189 case Bytecodes::_dload_1:
190 case Bytecodes::_aload_1:
191 push(local(1));
192 break;
193 case Bytecodes::_iload_2:
194 case Bytecodes::_lload_2:
195 case Bytecodes::_fload_2:
196 case Bytecodes::_dload_2:
197 case Bytecodes::_aload_2:
198 push(local(2));
985 special_result = LLVMValue::jlong_constant(0);
986 else
987 special_result = LLVMValue::jint_constant(0);
988 }
989 else {
990 special_result = a;
991 }
992 builder()->CreateBr(done);
993
994 builder()->SetInsertPoint(general_case);
995 Value *general_result;
996 if (is_rem)
997 general_result = builder()->CreateSRem(a, b);
998 else
999 general_result = builder()->CreateSDiv(a, b);
1000 builder()->CreateBr(done);
1001
1002 builder()->SetInsertPoint(done);
1003 PHINode *result;
1004 if (is_long)
1005 result = builder()->CreatePHI(SharkType::jlong_type(), 0, "result");
1006 else
1007 result = builder()->CreatePHI(SharkType::jint_type(), 0, "result");
1008 result->addIncoming(special_result, special_case);
1009 result->addIncoming(general_result, general_case);
1010
1011 if (is_long)
1012 push(SharkValue::create_jlong(result, false));
1013 else
1014 push(SharkValue::create_jint(result, false));
1015 }
1016
1017 void SharkBlock::do_field_access(bool is_get, bool is_field) {
1018 bool will_link;
1019 ciField *field = iter()->get_field(will_link);
1020 assert(will_link, "typeflow responsibility");
1021 assert(is_field != field->is_static(), "mismatch");
1022
1023 // Pop the value off the stack where necessary
1024 SharkValue *value = NULL;
1025 if (!is_get)
1026 value = pop();
1027
1028 // Find the object we're accessing, if necessary
1029 Value *object = NULL;
1030 if (is_field) {
1031 SharkValue *value = pop();
1032 check_null(value);
1033 object = value->generic_value();
1034 }
1035 if (is_get && field->is_constant()) {
1036 SharkConstant *constant = SharkConstant::for_field(iter());
1037 if (constant->is_loaded())
1038 value = constant->value(builder());
1039 }
1040 if (!is_get || value == NULL) {
1041 if (!is_field) {
1042 object = builder()->CreateInlineOop(field->holder()->java_mirror());
1043 }
1044 BasicType basic_type = field->type()->basic_type();
1045 Type *stack_type = SharkType::to_stackType(basic_type);
1046 Type *field_type = SharkType::to_arrayType(basic_type);
1047
1048 Value *addr = builder()->CreateAddressOfStructEntry(
1049 object, in_ByteSize(field->offset_in_bytes()),
1050 PointerType::getUnqual(field_type),
1051 "addr");
1052
1053 // Do the access
1054 if (is_get) {
1055 Value* field_value;
1056 if (field->is_volatile()) {
1057 #if SHARK_LLVM_VERSION <= 31
1058 field_value = builder()->CreateLoad(addr);
1059 #else
1060 field_value = builder()->CreateAtomicLoad(addr);
1061 #endif
1062 } else {
1063 field_value = builder()->CreateLoad(addr);
1064 }
1065 if (field_type != stack_type) {
1066 field_value = builder()->CreateIntCast(
1067 field_value, stack_type, basic_type != T_CHAR);
1068 }
1069
1070 value = SharkValue::create_generic(field->type(), field_value, false);
1071 }
1072 else {
1073 Value *field_value = value->generic_value();
1074
1075 if (field_type != stack_type) {
1076 field_value = builder()->CreateIntCast(
1077 field_value, field_type, basic_type != T_CHAR);
1078 }
1079
1080 if (field->is_volatile()) {
1081 #if SHARK_LLVM_VERSION <= 31
1082 builder()->CreateStore(field_value, addr);
1083 #else
1084 builder()->CreateAtomicStore(field_value, addr);
1085 #endif
1086 } else {
1087 builder()->CreateStore(field_value, addr);
1088 }
1089
1090 if (!field->type()->is_primitive_type()) {
1091 builder()->CreateUpdateBarrierSet(oopDesc::bs(), addr);
1092 }
1093 #if SHARK_LLVM_VERSION <= 31
1094 if (field->is_volatile()) {
1095 builder()->CreateMemoryBarrier(SharkBuilder::BARRIER_STORELOAD);
1096 }
1097 #endif
1098 }
1099 }
1100
1101 // Push the value onto the stack where necessary
1102 if (is_get)
1103 push(value);
1104 }
1105
1106 void SharkBlock::do_lcmp() {
1107 Value *b = pop()->jlong_value();
1108 Value *a = pop()->jlong_value();
1109
1110 BasicBlock *ip = builder()->GetBlockInsertionPoint();
1111 BasicBlock *ne = builder()->CreateBlock(ip, "lcmp_ne");
1112 BasicBlock *lt = builder()->CreateBlock(ip, "lcmp_lt");
1113 BasicBlock *gt = builder()->CreateBlock(ip, "lcmp_gt");
1114 BasicBlock *done = builder()->CreateBlock(ip, "done");
1115
1116 BasicBlock *eq = builder()->GetInsertBlock();
1117 builder()->CreateCondBr(builder()->CreateICmpEQ(a, b), done, ne);
1118
1119 builder()->SetInsertPoint(ne);
1120 builder()->CreateCondBr(builder()->CreateICmpSLT(a, b), lt, gt);
1121
1122 builder()->SetInsertPoint(lt);
1123 builder()->CreateBr(done);
1124
1125 builder()->SetInsertPoint(gt);
1126 builder()->CreateBr(done);
1127
1128 builder()->SetInsertPoint(done);
1129 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), 0, "result");
1130 result->addIncoming(LLVMValue::jint_constant(-1), lt);
1131 result->addIncoming(LLVMValue::jint_constant(0), eq);
1132 result->addIncoming(LLVMValue::jint_constant(1), gt);
1133
1134 push(SharkValue::create_jint(result, false));
1135 }
1136
1137 void SharkBlock::do_fcmp(bool is_double, bool unordered_is_greater) {
1138 Value *a, *b;
1139 if (is_double) {
1140 b = pop()->jdouble_value();
1141 a = pop()->jdouble_value();
1142 }
1143 else {
1144 b = pop()->jfloat_value();
1145 a = pop()->jfloat_value();
1146 }
1147
1148 BasicBlock *ip = builder()->GetBlockInsertionPoint();
1149 BasicBlock *ordered = builder()->CreateBlock(ip, "ordered");
1156 builder()->CreateCondBr(
1157 builder()->CreateFCmpUNO(a, b),
1158 unordered_is_greater ? gt : lt, ordered);
1159
1160 builder()->SetInsertPoint(ordered);
1161 builder()->CreateCondBr(builder()->CreateFCmpULT(a, b), lt, ge);
1162
1163 builder()->SetInsertPoint(ge);
1164 builder()->CreateCondBr(builder()->CreateFCmpUGT(a, b), gt, eq);
1165
1166 builder()->SetInsertPoint(lt);
1167 builder()->CreateBr(done);
1168
1169 builder()->SetInsertPoint(gt);
1170 builder()->CreateBr(done);
1171
1172 builder()->SetInsertPoint(eq);
1173 builder()->CreateBr(done);
1174
1175 builder()->SetInsertPoint(done);
1176 PHINode *result = builder()->CreatePHI(SharkType::jint_type(), 0, "result");
1177 result->addIncoming(LLVMValue::jint_constant(-1), lt);
1178 result->addIncoming(LLVMValue::jint_constant(0), eq);
1179 result->addIncoming(LLVMValue::jint_constant(1), gt);
1180
1181 push(SharkValue::create_jint(result, false));
1182 }
1183
1184 void SharkBlock::emit_IR() {
1185 ShouldNotCallThis();
1186 }
1187
1188 SharkState* SharkBlock::entry_state() {
1189 ShouldNotCallThis();
1190 }
1191
1192 void SharkBlock::do_zero_check(SharkValue* value) {
1193 ShouldNotCallThis();
1194 }
1195
1196 void SharkBlock::maybe_add_backedge_safepoint() {
|