Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: runtime/vm/simulator_dbc.cc

Issue 2418073002: DBC: Fix CheckClass bug. Add some intrinsics (Closed)
Patch Set: more intrinsics Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include <setjmp.h> // NOLINT 5 #include <setjmp.h> // NOLINT
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #if defined(TARGET_ARCH_DBC) 9 #if defined(TARGET_ARCH_DBC)
10 10
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 RawSmi* index = static_cast<RawSmi*>(args[1]); 232 RawSmi* index = static_cast<RawSmi*>(args[1]);
233 RawGrowableObjectArray* array = 233 RawGrowableObjectArray* array =
234 static_cast<RawGrowableObjectArray*>(args[0]); 234 static_cast<RawGrowableObjectArray*>(args[0]);
235 if (CheckIndex(index, array->ptr()->length_)) { 235 if (CheckIndex(index, array->ptr()->length_)) {
236 *result = array->ptr()->data_->ptr()->data()[Smi::Value(index)]; 236 *result = array->ptr()->data_->ptr()->data()[Smi::Value(index)];
237 return true; 237 return true;
238 } 238 }
239 return false; 239 return false;
240 } 240 }
241 241
242 static bool Double_getIsNan(Thread* thread,
243 RawObject** FP,
244 RawObject** result) {
245 RawObject** args = FrameArguments(FP, 1);
246 RawDouble* d = static_cast<RawDouble*>(args[0]);
247 *result = isnan(d->ptr()->value_)
248 ? Bool::True().raw()
249 : Bool::False().raw();
250 return true;
251 }
252
253 static bool ObjectEquals(Thread* thread,
254 RawObject** FP,
255 RawObject** result) {
256 RawObject** args = FrameArguments(FP, 2);
257 *result = args[0] == args[1] ? Bool::True().raw() : Bool::False().raw();
258 return true;
259 }
260
261 static bool ObjectRuntimeType(Thread* thread,
262 RawObject** FP,
263 RawObject** result) {
264 RawObject** args = FrameArguments(FP, 1);
265 const intptr_t cid = GetClassId(args[0]);
266 if (cid == kClosureCid) {
267 return false;
268 }
269 RawClass* cls = thread->isolate()->class_table()->At(cid);
270 if (cls->ptr()->num_type_arguments_ != 0) {
271 return false;
272 }
273 RawType* typ = cls->ptr()->canonical_type_;
274 if (typ == Object::null()) {
275 return false;
276 }
277 *result = static_cast<RawObject*>(typ);
278 return true;
279 }
280
281 static bool GetDoubleOperands(RawObject** args, double* d1, double* d2) {
282 RawObject* obj2 = args[1];
283 if (!obj2->IsHeapObject()) {
Florian Schneider 2016/10/17 16:58:54 I'd rather use obj2->IsSmi() for readability avoid
zra 2016/10/17 17:22:51 IsSmi() calls GetClassId() which calls ptr() which
284 *d2 = static_cast<double>(
285 reinterpret_cast<intptr_t>(obj2) >> kSmiTagSize);
286 } else if (obj2->GetClassId() == kDoubleCid) {
287 RawDouble* obj2d = static_cast<RawDouble*>(obj2);
288 *d2 = obj2d->ptr()->value_;
289 } else {
290 return false;
291 }
292 RawDouble* obj1 = static_cast<RawDouble*>(args[0]);
293 *d1 = obj1->ptr()->value_;
294 return true;
295 }
296
297 static bool Double_add(Thread* thread,
298 RawObject** FP,
299 RawObject** result) {
300 double d1, d2;
301 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
302 return false;
303 }
304 *result = static_cast<RawObject*>(Double::New(d1 + d2));
305 return true;
306 }
307
308 static bool Double_mul(Thread* thread,
309 RawObject** FP,
310 RawObject** result) {
311 double d1, d2;
312 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
313 return false;
314 }
315 *result = static_cast<RawObject*>(Double::New(d1 * d2));
316 return true;
317 }
318
319 static bool Double_sub(Thread* thread,
320 RawObject** FP,
321 RawObject** result) {
322 double d1, d2;
323 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
324 return false;
325 }
326 *result = static_cast<RawObject*>(Double::New(d1 - d2));
327 return true;
328 }
329
330 static bool Double_div(Thread* thread,
331 RawObject** FP,
332 RawObject** result) {
333 double d1, d2;
334 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
335 return false;
336 }
337 *result = static_cast<RawObject*>(Double::New(d1 / d2));
338 return true;
339 }
340
341 static bool Double_greaterThan(Thread* thread,
342 RawObject** FP,
343 RawObject** result) {
344 double d1, d2;
345 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
346 return false;
347 }
348 *result = d1 > d2 ? Bool::True().raw() : Bool::False().raw();
349 return true;
350 }
351
352 static bool Double_greaterEqualThan(Thread* thread,
353 RawObject** FP,
354 RawObject** result) {
355 double d1, d2;
356 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
357 return false;
358 }
359 *result = d1 >= d2 ? Bool::True().raw() : Bool::False().raw();
360 return true;
361 }
362
363 static bool Double_lessThan(Thread* thread,
364 RawObject** FP,
365 RawObject** result) {
366 double d1, d2;
367 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
368 return false;
369 }
370 *result = d1 < d2 ? Bool::True().raw() : Bool::False().raw();
371 return true;
372 }
373
374 static bool Double_equal(Thread* thread,
375 RawObject** FP,
376 RawObject** result) {
377 double d1, d2;
378 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
379 return false;
380 }
381 *result = d1 == d2 ? Bool::True().raw() : Bool::False().raw();
382 return true;
383 }
384
385 static bool Double_lessEqualThan(Thread* thread,
386 RawObject** FP,
387 RawObject** result) {
388 double d1, d2;
389 if (!GetDoubleOperands(FrameArguments(FP, 2), &d1, &d2)) {
390 return false;
391 }
392 *result = d1 <= d2 ? Bool::True().raw() : Bool::False().raw();
393 return true;
394 }
395
242 DART_FORCE_INLINE static RawCode* FrameCode(RawObject** FP) { 396 DART_FORCE_INLINE static RawCode* FrameCode(RawObject** FP) {
243 ASSERT(GetClassId(FP[kPcMarkerSlotFromFp]) == kCodeCid); 397 ASSERT(GetClassId(FP[kPcMarkerSlotFromFp]) == kCodeCid);
244 return static_cast<RawCode*>(FP[kPcMarkerSlotFromFp]); 398 return static_cast<RawCode*>(FP[kPcMarkerSlotFromFp]);
245 } 399 }
246 400
247 401
248 DART_FORCE_INLINE static void SetFrameCode(RawObject** FP, RawCode* code) { 402 DART_FORCE_INLINE static void SetFrameCode(RawObject** FP, RawCode* code) {
249 ASSERT(GetClassId(code) == kCodeCid); 403 ASSERT(GetClassId(code) == kCodeCid);
250 FP[kPcMarkerSlotFromFp] = code; 404 FP[kPcMarkerSlotFromFp] = code;
251 } 405 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 437 }
284 438
285 intrinsics_[kObjectArraySetIndexedIntrinsic] = 439 intrinsics_[kObjectArraySetIndexedIntrinsic] =
286 SimulatorHelpers::ObjectArraySetIndexed; 440 SimulatorHelpers::ObjectArraySetIndexed;
287 intrinsics_[kObjectArrayGetIndexedIntrinsic] = 441 intrinsics_[kObjectArrayGetIndexedIntrinsic] =
288 SimulatorHelpers::ObjectArrayGetIndexed; 442 SimulatorHelpers::ObjectArrayGetIndexed;
289 intrinsics_[kGrowableArraySetIndexedIntrinsic] = 443 intrinsics_[kGrowableArraySetIndexedIntrinsic] =
290 SimulatorHelpers::GrowableArraySetIndexed; 444 SimulatorHelpers::GrowableArraySetIndexed;
291 intrinsics_[kGrowableArrayGetIndexedIntrinsic] = 445 intrinsics_[kGrowableArrayGetIndexedIntrinsic] =
292 SimulatorHelpers::GrowableArrayGetIndexed; 446 SimulatorHelpers::GrowableArrayGetIndexed;
447 intrinsics_[kObjectEqualsIntrinsic] =
448 SimulatorHelpers::ObjectEquals;
449 intrinsics_[kObjectRuntimeTypeIntrinsic] =
450 SimulatorHelpers::ObjectRuntimeType;
451
452 intrinsics_[kDouble_getIsNaNIntrinsic] =
453 SimulatorHelpers::Double_getIsNan;
454 intrinsics_[kDouble_addIntrinsic] =
455 SimulatorHelpers::Double_add;
456 intrinsics_[kDouble_mulIntrinsic] =
457 SimulatorHelpers::Double_mul;
458 intrinsics_[kDouble_subIntrinsic] =
459 SimulatorHelpers::Double_sub;
460 intrinsics_[kDouble_divIntrinsic] =
461 SimulatorHelpers::Double_div;
462 intrinsics_[kDouble_greaterThanIntrinsic] =
463 SimulatorHelpers::Double_greaterThan;
464 intrinsics_[kDouble_greaterEqualThanIntrinsic] =
465 SimulatorHelpers::Double_greaterEqualThan;
466 intrinsics_[kDouble_lessThanIntrinsic] =
467 SimulatorHelpers::Double_lessThan;
468 intrinsics_[kDouble_equalIntrinsic] =
469 SimulatorHelpers::Double_equal;
470 intrinsics_[kDouble_lessEqualThanIntrinsic] =
471 SimulatorHelpers::Double_lessEqualThan;
293 } 472 }
294 473
295 474
296 Simulator::Simulator() 475 Simulator::Simulator()
297 : stack_(NULL), 476 : stack_(NULL),
298 fp_(NULL), 477 fp_(NULL),
299 sp_(NULL) { 478 sp_(NULL) {
300 // Setup simulator support first. Some of this information is needed to 479 // Setup simulator support first. Some of this information is needed to
301 // setup the architecture state. 480 // setup the architecture state.
302 // We allocate the stack here, the size is computed as the sum of 481 // We allocate the stack here, the size is computed as the sum of
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 const bool may_be_smi = (rB == 1); 3054 const bool may_be_smi = (rB == 1);
2876 const intptr_t cids_length = rC; 3055 const intptr_t cids_length = rC;
2877 if (LIKELY(!is_smi)) { 3056 if (LIKELY(!is_smi)) {
2878 const intptr_t cid = SimulatorHelpers::GetClassId(FP[rA]); 3057 const intptr_t cid = SimulatorHelpers::GetClassId(FP[rA]);
2879 for (intptr_t i = 0; i < cids_length; i++) { 3058 for (intptr_t i = 0; i < cids_length; i++) {
2880 const intptr_t desired_cid = Bytecode::DecodeD(*(pc + i)); 3059 const intptr_t desired_cid = Bytecode::DecodeD(*(pc + i));
2881 if (cid == desired_cid) { 3060 if (cid == desired_cid) {
2882 pc++; 3061 pc++;
2883 break; 3062 break;
2884 } 3063 }
2885 // The cids are sorted in descending order.
2886 if (cid > desired_cid) {
2887 break;
2888 }
2889 } 3064 }
2890 pc += cids_length; 3065 pc += cids_length;
2891 } else { 3066 } else {
2892 pc += cids_length; 3067 pc += cids_length;
2893 pc += (may_be_smi ? 1 : 0); 3068 pc += (may_be_smi ? 1 : 0);
2894 } 3069 }
2895 DISPATCH(); 3070 DISPATCH();
2896 } 3071 }
2897 3072
2898 { 3073 {
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
3494 pc_ = pc; 3669 pc_ = pc;
3495 special_[kExceptionSpecialIndex] = raw_exception; 3670 special_[kExceptionSpecialIndex] = raw_exception;
3496 special_[kStacktraceSpecialIndex] = raw_stacktrace; 3671 special_[kStacktraceSpecialIndex] = raw_stacktrace;
3497 buf->Longjmp(); 3672 buf->Longjmp();
3498 UNREACHABLE(); 3673 UNREACHABLE();
3499 } 3674 }
3500 3675
3501 } // namespace dart 3676 } // namespace dart
3502 3677
3503 #endif // defined TARGET_ARCH_DBC 3678 #endif // defined TARGET_ARCH_DBC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698