Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/arguments-inl.h"
6 : #include "src/conversions-inl.h"
7 : #include "src/counters.h"
8 : #include "src/heap/factory.h"
9 : #include "src/objects/hash-table-inl.h"
10 : #include "src/objects/js-collection-inl.h"
11 : #include "src/runtime/runtime-utils.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 10 : RUNTIME_FUNCTION(Runtime_TheHole) {
17 : SealHandleScope shs(isolate);
18 : DCHECK_EQ(0, args.length());
19 : return ReadOnlyRoots(isolate).the_hole_value();
20 : }
21 :
22 166560 : RUNTIME_FUNCTION(Runtime_SetGrow) {
23 166560 : HandleScope scope(isolate);
24 : DCHECK_EQ(1, args.length());
25 333120 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
26 333120 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
27 166560 : table = OrderedHashSet::EnsureGrowable(isolate, table);
28 333120 : holder->set_table(*table);
29 166560 : return ReadOnlyRoots(isolate).undefined_value();
30 : }
31 :
32 :
33 811 : RUNTIME_FUNCTION(Runtime_SetShrink) {
34 811 : HandleScope scope(isolate);
35 : DCHECK_EQ(1, args.length());
36 1622 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
37 1622 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
38 811 : table = OrderedHashSet::Shrink(isolate, table);
39 1622 : holder->set_table(*table);
40 811 : return ReadOnlyRoots(isolate).undefined_value();
41 : }
42 :
43 161414 : RUNTIME_FUNCTION(Runtime_MapShrink) {
44 161414 : HandleScope scope(isolate);
45 : DCHECK_EQ(1, args.length());
46 322828 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
47 322828 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
48 161414 : table = OrderedHashMap::Shrink(isolate, table);
49 322828 : holder->set_table(*table);
50 161414 : return ReadOnlyRoots(isolate).undefined_value();
51 : }
52 :
53 3885 : RUNTIME_FUNCTION(Runtime_MapGrow) {
54 3885 : HandleScope scope(isolate);
55 : DCHECK_EQ(1, args.length());
56 7770 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
57 7770 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
58 3885 : table = OrderedHashMap::EnsureGrowable(isolate, table);
59 7770 : holder->set_table(*table);
60 3885 : return ReadOnlyRoots(isolate).undefined_value();
61 : }
62 :
63 0 : RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
64 0 : HandleScope scope(isolate);
65 : DCHECK_EQ(3, args.length());
66 0 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
67 0 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
68 0 : CONVERT_SMI_ARG_CHECKED(hash, 2)
69 :
70 : #ifdef DEBUG
71 : DCHECK(key->IsJSReceiver());
72 : DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key));
73 : Handle<EphemeronHashTable> table(
74 : EphemeronHashTable::cast(weak_collection->table()), isolate);
75 : // Should only be called when shrinking the table is necessary. See
76 : // HashTable::Shrink().
77 : DCHECK(table->NumberOfElements() - 1 <= (table->Capacity() >> 2) &&
78 : table->NumberOfElements() - 1 >= 16);
79 : #endif
80 :
81 0 : bool was_present = JSWeakCollection::Delete(weak_collection, key, hash);
82 0 : return isolate->heap()->ToBoolean(was_present);
83 : }
84 :
85 312 : RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
86 312 : HandleScope scope(isolate);
87 : DCHECK_EQ(4, args.length());
88 624 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
89 312 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
90 312 : CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
91 624 : CONVERT_SMI_ARG_CHECKED(hash, 3)
92 :
93 : #ifdef DEBUG
94 : DCHECK(key->IsJSReceiver());
95 : DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key));
96 : Handle<EphemeronHashTable> table(
97 : EphemeronHashTable::cast(weak_collection->table()), isolate);
98 : // Should only be called when rehashing or resizing the table is necessary.
99 : // See EphemeronHashTable::Put() and HashTable::HasSufficientCapacityToAdd().
100 : DCHECK((table->NumberOfDeletedElements() << 1) > table->NumberOfElements() ||
101 : !table->HasSufficientCapacityToAdd(1));
102 : #endif
103 :
104 312 : JSWeakCollection::Set(weak_collection, key, value, hash);
105 312 : return *weak_collection;
106 : }
107 :
108 : } // namespace internal
109 183867 : } // namespace v8
|