1d7ca12fdc
Add GC-friendly replacement for default Map/Set: * open-addressing hash table, avoiding the overhead of chained entries * index separate from the keys/values, allowing more of it to fit in the cache * new keys are always appended, to allow insertion-order iteration * spare bits in index entries are used to store hashes * index is typed data, so can be ignored by GC Enable it with --use_compact_hash (disabled by default). Reduces Dart2JS compilation time for huge codebase (N=200) by ~30%, due to reduced time in GC. Slightly slower for small maps and maps with deletions: json benchmarks regress by ~5%. R=vegorov@google.com Review URL: https://codereview.chromium.org//915323002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43840 260f80e4-7a28-3924-810f-c04153c831b5
105 lines
3.1 KiB
C++
105 lines
3.1 KiB
C++
// Copyright (c) 2014, 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 "platform/assert.h"
|
|
|
|
#include "vm/assembler.h"
|
|
#include "vm/bootstrap_natives.h"
|
|
#include "vm/exceptions.h"
|
|
#include "vm/flags.h"
|
|
#include "vm/native_entry.h"
|
|
#include "vm/object.h"
|
|
|
|
namespace dart {
|
|
|
|
DEFINE_FLAG(bool, use_internal_hash_map, false, "Use internal hash map.");
|
|
DEFINE_FLAG(bool, use_compact_hash, false, "Use compact hash map and set.");
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_allocate, 1) {
|
|
const TypeArguments& type_arguments =
|
|
TypeArguments::CheckedHandle(arguments->NativeArgAt(0));
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::Handle(LinkedHashMap::New());
|
|
map.SetTypeArguments(type_arguments);
|
|
return map.raw();
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_getLength, 1) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
return Smi::New(map.Length());
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_lookUp, 2) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
GET_NON_NULL_NATIVE_ARGUMENT(Instance, key, arguments->NativeArgAt(1));
|
|
return map.LookUp(key);
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_containsKey, 2) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
GET_NON_NULL_NATIVE_ARGUMENT(Instance, key, arguments->NativeArgAt(1));
|
|
return Bool::Get(map.Contains(key)).raw();
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_insertOrUpdate, 3) {
|
|
LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
GET_NON_NULL_NATIVE_ARGUMENT(Instance, key, arguments->NativeArgAt(1));
|
|
GET_NON_NULL_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(2));
|
|
map.InsertOrUpdate(key, value);
|
|
return Object::null();
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_remove, 2) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
GET_NON_NULL_NATIVE_ARGUMENT(Instance, key, arguments->NativeArgAt(1));
|
|
return map.Remove(key);
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_clear, 1) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
map.Clear();
|
|
return Object::null();
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_toArray, 1) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
return map.ToArray();
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_getModMark, 2) {
|
|
const LinkedHashMap& map =
|
|
LinkedHashMap::CheckedHandle(arguments->NativeArgAt(0));
|
|
GET_NON_NULL_NATIVE_ARGUMENT(Bool, create, arguments->NativeArgAt(1));
|
|
return map.GetModificationMark(create.value());
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_useInternal, 0) {
|
|
ASSERT(!(FLAG_use_internal_hash_map && FLAG_use_compact_hash));
|
|
return Bool::Get(FLAG_use_internal_hash_map).raw();
|
|
}
|
|
|
|
|
|
DEFINE_NATIVE_ENTRY(LinkedHashMap_useCompact, 0) {
|
|
ASSERT(!(FLAG_use_internal_hash_map && FLAG_use_compact_hash));
|
|
return Bool::Get(FLAG_use_compact_hash).raw();
|
|
}
|
|
|
|
} // namespace dart
|