@@ -256,6 +256,28 @@ DART_FORCE_INLINE static RawObject* InitializeHeader(uword addr,
256256 return RawObject::FromAddr (addr);
257257}
258258
259+ DART_FORCE_INLINE static bool TryAllocate (Thread* thread,
260+ intptr_t class_id,
261+ intptr_t instance_size,
262+ RawObject** result) {
263+ const uword start = thread->top ();
264+ #ifndef PRODUCT
265+ ClassTable* table = thread->isolate ()->class_table ();
266+ if (UNLIKELY (table->TraceAllocationFor (class_id))) {
267+ return false ;
268+ }
269+ #endif
270+ if (LIKELY ((start + instance_size) < thread->end ())) {
271+ thread->set_top (start + instance_size);
272+ #ifndef PRODUCT
273+ table->UpdateAllocatedNew (class_id, instance_size);
274+ #endif
275+ *result = InitializeHeader (start, class_id, instance_size);
276+ return true ;
277+ }
278+ return false ;
279+ }
280+
259281void LookupCache::Clear () {
260282 for (intptr_t i = 0 ; i < kNumEntries ; i++) {
261283 entries_[i].receiver_cid = kIllegalCid ;
@@ -1351,14 +1373,9 @@ DART_NOINLINE bool Interpreter::AllocateMint(Thread* thread,
13511373 RawObject** FP,
13521374 RawObject** SP) {
13531375 ASSERT (!Smi::IsValid (value));
1354- const intptr_t instance_size = Mint::InstanceSize ();
1355- const uword start = thread->top ();
1356- if (LIKELY ((start + instance_size) < thread->end ())) {
1357- thread->set_top (start + instance_size);
1358- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1359- kMintCid , instance_size));
1360- RawMint* result =
1361- Mint::RawCast (InitializeHeader (start, kMintCid , instance_size));
1376+ RawMint* result;
1377+ if (TryAllocate (thread, kMintCid , Mint::InstanceSize (),
1378+ reinterpret_cast <RawObject**>(&result))) {
13621379 result->ptr ()->value_ = value;
13631380 SP[0 ] = result;
13641381 return true ;
@@ -1383,14 +1400,9 @@ DART_NOINLINE bool Interpreter::AllocateDouble(Thread* thread,
13831400 const KBCInstr* pc,
13841401 RawObject** FP,
13851402 RawObject** SP) {
1386- const intptr_t instance_size = Double::InstanceSize ();
1387- const uword start = thread->top ();
1388- if (LIKELY ((start + instance_size) < thread->end ())) {
1389- thread->set_top (start + instance_size);
1390- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1391- kDoubleCid , instance_size));
1392- RawDouble* result =
1393- Double::RawCast (InitializeHeader (start, kDoubleCid , instance_size));
1403+ RawDouble* result;
1404+ if (TryAllocate (thread, kDoubleCid , Double::InstanceSize (),
1405+ reinterpret_cast <RawObject**>(&result))) {
13941406 result->ptr ()->value_ = value;
13951407 SP[0 ] = result;
13961408 return true ;
@@ -1415,14 +1427,9 @@ DART_NOINLINE bool Interpreter::AllocateFloat32x4(Thread* thread,
14151427 const KBCInstr* pc,
14161428 RawObject** FP,
14171429 RawObject** SP) {
1418- const intptr_t instance_size = Float32x4::InstanceSize ();
1419- const uword start = thread->top ();
1420- if (LIKELY ((start + instance_size) < thread->end ())) {
1421- thread->set_top (start + instance_size);
1422- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1423- kFloat32x4Cid , instance_size));
1424- RawFloat32x4* result = Float32x4::RawCast (
1425- InitializeHeader (start, kFloat32x4Cid , instance_size));
1430+ RawFloat32x4* result;
1431+ if (TryAllocate (thread, kFloat32x4Cid , Float32x4::InstanceSize (),
1432+ reinterpret_cast <RawObject**>(&result))) {
14261433 value.writeTo (result->ptr ()->value_ );
14271434 SP[0 ] = result;
14281435 return true ;
@@ -1447,14 +1454,9 @@ DART_NOINLINE bool Interpreter::AllocateFloat64x2(Thread* thread,
14471454 const KBCInstr* pc,
14481455 RawObject** FP,
14491456 RawObject** SP) {
1450- const intptr_t instance_size = Float64x2::InstanceSize ();
1451- const uword start = thread->top ();
1452- if (LIKELY ((start + instance_size) < thread->end ())) {
1453- thread->set_top (start + instance_size);
1454- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1455- kFloat64x2Cid , instance_size));
1456- RawFloat64x2* result = Float64x2::RawCast (
1457- InitializeHeader (start, kFloat64x2Cid , instance_size));
1457+ RawFloat64x2* result;
1458+ if (TryAllocate (thread, kFloat64x2Cid , Float64x2::InstanceSize (),
1459+ reinterpret_cast <RawObject**>(&result))) {
14581460 value.writeTo (result->ptr ()->value_ );
14591461 SP[0 ] = result;
14601462 return true ;
@@ -1483,14 +1485,9 @@ bool Interpreter::AllocateArray(Thread* thread,
14831485 if (LIKELY (!length_object->IsHeapObject ())) {
14841486 const intptr_t length = Smi::Value (Smi::RawCast (length_object));
14851487 if (LIKELY (Array::IsValidLength (length))) {
1486- const intptr_t instance_size = Array::InstanceSize (length);
1487- const uword start = thread->top ();
1488- if (LIKELY ((start + instance_size) < thread->end ())) {
1489- thread->set_top (start + instance_size);
1490- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1491- kArrayCid , instance_size));
1492- RawArray* result =
1493- Array::RawCast (InitializeHeader (start, kArrayCid , instance_size));
1488+ RawArray* result;
1489+ if (TryAllocate (thread, kArrayCid , Array::InstanceSize (length),
1490+ reinterpret_cast <RawObject**>(&result))) {
14941491 result->ptr ()->type_arguments_ = type_args;
14951492 result->ptr ()->length_ = Smi::New (length);
14961493 for (intptr_t i = 0 ; i < length; i++) {
@@ -1517,21 +1514,15 @@ bool Interpreter::AllocateContext(Thread* thread,
15171514 const KBCInstr* pc,
15181515 RawObject** FP,
15191516 RawObject** SP) {
1520- const intptr_t instance_size = Context::InstanceSize (num_context_variables);
1521- ASSERT (Utils::IsAligned (instance_size, kObjectAlignment ));
1522- const uword start = thread->top ();
1523- if (LIKELY ((start + instance_size) < thread->end ())) {
1524- thread->set_top (start + instance_size);
1525- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1526- kContextCid , instance_size));
1527- RawContext* result =
1528- Context::RawCast (InitializeHeader (start, kContextCid , instance_size));
1517+ RawContext* result;
1518+ if (TryAllocate (thread, kContextCid ,
1519+ Context::InstanceSize (num_context_variables),
1520+ reinterpret_cast <RawObject**>(&result))) {
15291521 result->ptr ()->num_variables_ = num_context_variables;
15301522 RawObject* null_value = Object::null ();
15311523 result->ptr ()->parent_ = static_cast <RawContext*>(null_value);
1532- for (intptr_t offset = sizeof (RawContext); offset < instance_size;
1533- offset += kWordSize ) {
1534- *reinterpret_cast <RawObject**>(start + offset) = null_value;
1524+ for (intptr_t i = 0 ; i < num_context_variables; i++) {
1525+ result->ptr ()->data ()[i] = null_value;
15351526 }
15361527 SP[0 ] = result;
15371528 return true ;
@@ -1551,13 +1542,10 @@ bool Interpreter::AllocateClosure(Thread* thread,
15511542 RawObject** FP,
15521543 RawObject** SP) {
15531544 const intptr_t instance_size = Closure::InstanceSize ();
1554- const uword start = thread->top ();
1555- if (LIKELY ((start + instance_size) < thread->end ())) {
1556- thread->set_top (start + instance_size);
1557- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
1558- kClosureCid , instance_size));
1559- RawClosure* result =
1560- Closure::RawCast (InitializeHeader (start, kClosureCid , instance_size));
1545+ RawClosure* result;
1546+ if (TryAllocate (thread, kClosureCid , instance_size,
1547+ reinterpret_cast <RawObject**>(&result))) {
1548+ uword start = RawObject::ToAddr (result);
15611549 RawObject* null_value = Object::null ();
15621550 for (intptr_t offset = sizeof (RawInstance); offset < instance_size;
15631551 offset += kWordSize ) {
@@ -2492,12 +2480,9 @@ RawObject* Interpreter::Call(RawFunction* function,
24922480 const intptr_t class_id = cls->ptr ()->id_ ;
24932481 const intptr_t instance_size = cls->ptr ()->instance_size_in_words_
24942482 << kWordSizeLog2 ;
2495- const uword start = thread->top ();
2496- if (LIKELY ((start + instance_size) < thread->end ())) {
2497- thread->set_top (start + instance_size);
2498- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
2499- class_id, instance_size));
2500- RawObject* result = InitializeHeader (start, class_id, instance_size);
2483+ RawObject* result;
2484+ if (TryAllocate (thread, class_id, instance_size, &result)) {
2485+ uword start = RawObject::ToAddr (result);
25012486 for (intptr_t offset = sizeof (RawInstance); offset < instance_size;
25022487 offset += kWordSize ) {
25032488 *reinterpret_cast <RawObject**>(start + offset) = null_value;
@@ -2525,12 +2510,9 @@ RawObject* Interpreter::Call(RawFunction* function,
25252510 const intptr_t class_id = cls->ptr ()->id_ ;
25262511 const intptr_t instance_size = cls->ptr ()->instance_size_in_words_
25272512 << kWordSizeLog2 ;
2528- const uword start = thread->top ();
2529- if (LIKELY ((start + instance_size) < thread->end ())) {
2530- thread->set_top (start + instance_size);
2531- NOT_IN_PRODUCT (thread->isolate ()->class_table ()->UpdateAllocatedNew (
2532- class_id, instance_size));
2533- RawObject* result = InitializeHeader (start, class_id, instance_size);
2513+ RawObject* result;
2514+ if (TryAllocate (thread, class_id, instance_size, &result)) {
2515+ uword start = RawObject::ToAddr (result);
25342516 for (intptr_t offset = sizeof (RawInstance); offset < instance_size;
25352517 offset += kWordSize ) {
25362518 *reinterpret_cast <RawObject**>(start + offset) = null_value;
0 commit comments