154 SharkValue *sb = state()->pop();
155 SharkValue *sa = state()->pop();
156 Value *a = sa->jint_value();
157 Value *b = sb->jint_value();
158
159 // Perform the test
160 BasicBlock *ip = builder()->GetBlockInsertionPoint();
161 BasicBlock *return_a = builder()->CreateBlock(ip, "return_a");
162 BasicBlock *return_b = builder()->CreateBlock(ip, "return_b");
163 BasicBlock *done = builder()->CreateBlock(ip, "done");
164
165 builder()->CreateCondBr(builder()->CreateICmp(p, a, b), return_a, return_b);
166
167 builder()->SetInsertPoint(return_a);
168 builder()->CreateBr(done);
169
170 builder()->SetInsertPoint(return_b);
171 builder()->CreateBr(done);
172
173 builder()->SetInsertPoint(done);
174 PHINode *phi = builder()->CreatePHI(a->getType(), "result");
175 phi->addIncoming(a, return_a);
176 phi->addIncoming(b, return_b);
177
178 // Push the result
179 state()->push(
180 SharkValue::create_jint(
181 phi,
182 sa->zero_checked() && sb->zero_checked()));
183 }
184
185 void SharkIntrinsics::do_Math_1to1(Value *function) {
186 SharkValue *empty = state()->pop();
187 assert(empty == NULL, "should be");
188 state()->push(
189 SharkValue::create_jdouble(
190 builder()->CreateCall(
191 function, state()->pop()->jdouble_value())));
192 state()->push(NULL);
193 }
194
195 void SharkIntrinsics::do_Math_2to1(Value *function) {
196 SharkValue *empty = state()->pop();
197 assert(empty == NULL, "should be");
198 Value *y = state()->pop()->jdouble_value();
199 empty = state()->pop();
200 assert(empty == NULL, "should be");
201 Value *x = state()->pop()->jdouble_value();
202
203 state()->push(
204 SharkValue::create_jdouble(
205 builder()->CreateCall2(function, x, y)));
206 state()->push(NULL);
207 }
208
209 void SharkIntrinsics::do_Object_getClass() {
210 Value *klass = builder()->CreateValueOfStructEntry(
211 state()->pop()->jobject_value(),
212 in_ByteSize(oopDesc::klass_offset_in_bytes()),
213 SharkType::oop_type(),
214 "klass");
215
216 state()->push(
217 SharkValue::create_jobject(
218 builder()->CreateValueOfStructEntry(
219 klass,
220 Klass::java_mirror_offset(),
221 SharkType::oop_type(),
222 "java_mirror"),
223 true));
224 }
225
226 void SharkIntrinsics::do_System_currentTimeMillis() {
227 state()->push(
228 SharkValue::create_jlong(
229 builder()->CreateCall(builder()->current_time_millis()),
230 false));
231 state()->push(NULL);
232 }
233
248 SharkValue *empty = state()->pop();
249 assert(empty == NULL, "should be");
250 Value *offset = state()->pop()->jlong_value();
251 Value *object = state()->pop()->jobject_value();
252 Value *unsafe = state()->pop()->jobject_value();
253
254 // Convert the offset
255 offset = builder()->CreateCall(
256 builder()->unsafe_field_offset_to_byte_offset(),
257 offset);
258
259 // Locate the field
260 Value *addr = builder()->CreateIntToPtr(
261 builder()->CreateAdd(
262 builder()->CreatePtrToInt(object, SharkType::intptr_type()),
263 builder()->CreateIntCast(offset, SharkType::intptr_type(), true)),
264 PointerType::getUnqual(SharkType::jint_type()),
265 "addr");
266
267 // Perform the operation
268 Value *result = builder()->CreateCmpxchgInt(x, addr, e);
269
270 // Push the result
271 state()->push(
272 SharkValue::create_jint(
273 builder()->CreateIntCast(
274 builder()->CreateICmpEQ(result, e), SharkType::jint_type(), true),
275 false));
276 }
|
154 SharkValue *sb = state()->pop();
155 SharkValue *sa = state()->pop();
156 Value *a = sa->jint_value();
157 Value *b = sb->jint_value();
158
159 // Perform the test
160 BasicBlock *ip = builder()->GetBlockInsertionPoint();
161 BasicBlock *return_a = builder()->CreateBlock(ip, "return_a");
162 BasicBlock *return_b = builder()->CreateBlock(ip, "return_b");
163 BasicBlock *done = builder()->CreateBlock(ip, "done");
164
165 builder()->CreateCondBr(builder()->CreateICmp(p, a, b), return_a, return_b);
166
167 builder()->SetInsertPoint(return_a);
168 builder()->CreateBr(done);
169
170 builder()->SetInsertPoint(return_b);
171 builder()->CreateBr(done);
172
173 builder()->SetInsertPoint(done);
174 PHINode *phi = builder()->CreatePHI(a->getType(), 0, "result");
175 phi->addIncoming(a, return_a);
176 phi->addIncoming(b, return_b);
177
178 // Push the result
179 state()->push(
180 SharkValue::create_jint(
181 phi,
182 sa->zero_checked() && sb->zero_checked()));
183 }
184
185 void SharkIntrinsics::do_Math_1to1(Value *function) {
186 SharkValue *empty = state()->pop();
187 assert(empty == NULL, "should be");
188 state()->push(
189 SharkValue::create_jdouble(
190 builder()->CreateCall(
191 function, state()->pop()->jdouble_value())));
192 state()->push(NULL);
193 }
194
195 void SharkIntrinsics::do_Math_2to1(Value *function) {
196 SharkValue *empty = state()->pop();
197 assert(empty == NULL, "should be");
198 Value *y = state()->pop()->jdouble_value();
199 empty = state()->pop();
200 assert(empty == NULL, "should be");
201 Value *x = state()->pop()->jdouble_value();
202
203 state()->push(
204 SharkValue::create_jdouble(
205 builder()->CreateCall2(function, x, y)));
206 state()->push(NULL);
207 }
208
209 void SharkIntrinsics::do_Object_getClass() {
210 Value *klass = builder()->CreateValueOfStructEntry(
211 state()->pop()->jobject_value(),
212 in_ByteSize(oopDesc::klass_offset_in_bytes()),
213 SharkType::klass_type(),
214 "klass");
215
216 state()->push(
217 SharkValue::create_jobject(
218 builder()->CreateValueOfStructEntry(
219 klass,
220 Klass::java_mirror_offset(),
221 SharkType::oop_type(),
222 "java_mirror"),
223 true));
224 }
225
226 void SharkIntrinsics::do_System_currentTimeMillis() {
227 state()->push(
228 SharkValue::create_jlong(
229 builder()->CreateCall(builder()->current_time_millis()),
230 false));
231 state()->push(NULL);
232 }
233
248 SharkValue *empty = state()->pop();
249 assert(empty == NULL, "should be");
250 Value *offset = state()->pop()->jlong_value();
251 Value *object = state()->pop()->jobject_value();
252 Value *unsafe = state()->pop()->jobject_value();
253
254 // Convert the offset
255 offset = builder()->CreateCall(
256 builder()->unsafe_field_offset_to_byte_offset(),
257 offset);
258
259 // Locate the field
260 Value *addr = builder()->CreateIntToPtr(
261 builder()->CreateAdd(
262 builder()->CreatePtrToInt(object, SharkType::intptr_type()),
263 builder()->CreateIntCast(offset, SharkType::intptr_type(), true)),
264 PointerType::getUnqual(SharkType::jint_type()),
265 "addr");
266
267 // Perform the operation
268 Value *result = builder()->CreateAtomicCmpXchg(addr, e, x, llvm::SequentiallyConsistent);
269 // Push the result
270 state()->push(
271 SharkValue::create_jint(
272 builder()->CreateIntCast(
273 builder()->CreateICmpEQ(result, e), SharkType::jint_type(), true),
274 false));
275 }
|