dart-sdk/runtime/vm/assembler_test.cc
iposva@google.com 083c9e5e95 - Remember the fact that an object has been added to the
store buffer by a bit in the header.
- This bit can be used to filter out redundant additions
  into the store buffer making the dedup sets not needed.
- Remove the need for a HashSet when remembering old to
  new references.

Review URL: https://codereview.chromium.org//14307013

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22393 260f80e4-7a28-3924-810f-c04153c831b5
2013-05-03 20:59:42 +00:00

75 lines
3.2 KiB
C++

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/assembler.h"
#include "vm/globals.h"
#include "vm/os.h"
#include "vm/simulator.h"
#include "vm/unit_test.h"
#include "vm/virtual_memory.h"
namespace dart {
ASSEMBLER_TEST_EXTERN(StoreIntoObject);
ASSEMBLER_TEST_RUN(StoreIntoObject, test) {
#if defined(USING_SIMULATOR)
#define test_code(ctx, value, growable_array) \
Simulator::Current()->Call( \
bit_cast<int32_t, uword>(test->entry()), \
reinterpret_cast<int32_t>(ctx), \
reinterpret_cast<int32_t>(value), \
reinterpret_cast<int32_t>(growable_array), \
0)
#else
typedef void (*StoreData)(RawContext* ctx,
RawObject* value,
RawObject* growable_array);
StoreData test_code = reinterpret_cast<StoreData>(test->entry());
#endif
const Array& old_array = Array::Handle(Array::New(3, Heap::kOld));
const Array& new_array = Array::Handle(Array::New(3, Heap::kNew));
const GrowableObjectArray& grow_old_array = GrowableObjectArray::Handle(
GrowableObjectArray::New(old_array, Heap::kOld));
const GrowableObjectArray& grow_new_array = GrowableObjectArray::Handle(
GrowableObjectArray::New(old_array, Heap::kNew));
Smi& smi = Smi::Handle();
const Context& ctx = Context::Handle(Context::New(0));
EXPECT(old_array.raw() == grow_old_array.data());
EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw()));
EXPECT(old_array.raw() == grow_new_array.data());
EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw()));
// Store Smis into the old object.
for (int i = -128; i < 128; i++) {
smi = Smi::New(i);
test_code(ctx.raw(), smi.raw(), grow_old_array.raw());
EXPECT(reinterpret_cast<RawArray*>(smi.raw()) == grow_old_array.data());
EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw()));
}
// Store an old object into the old object.
test_code(ctx.raw(), old_array.raw(), grow_old_array.raw());
EXPECT(old_array.raw() == grow_old_array.data());
EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_old_array.raw()));
// Store a new object into the old object.
test_code(ctx.raw(), new_array.raw(), grow_old_array.raw());
EXPECT(new_array.raw() == grow_old_array.data());
EXPECT(Isolate::Current()->store_buffer()->Contains(grow_old_array.raw()));
// Store a new object into the new object.
test_code(ctx.raw(), new_array.raw(), grow_new_array.raw());
EXPECT(new_array.raw() == grow_new_array.data());
EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw()));
// Store an old object into the new object.
test_code(ctx.raw(), old_array.raw(), grow_new_array.raw());
EXPECT(old_array.raw() == grow_new_array.data());
EXPECT(!Isolate::Current()->store_buffer()->Contains(grow_new_array.raw()));
}
} // namespace dart