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/heap/heap-inl.h" // For ToBoolean. TODO(jkummerow): Drop.
10 : #include "src/objects/hash-table-inl.h"
11 : #include "src/objects/js-collection-inl.h"
12 : #include "src/runtime/runtime-utils.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 :
17 10 : RUNTIME_FUNCTION(Runtime_TheHole) {
18 : SealHandleScope shs(isolate);
19 : DCHECK_EQ(0, args.length());
20 : return ReadOnlyRoots(isolate).the_hole_value();
21 : }
22 :
23 166330 : RUNTIME_FUNCTION(Runtime_SetGrow) {
24 166330 : HandleScope scope(isolate);
25 : DCHECK_EQ(1, args.length());
26 332660 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
27 332660 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
28 166330 : table = OrderedHashSet::EnsureGrowable(isolate, table);
29 332660 : holder->set_table(*table);
30 166330 : return ReadOnlyRoots(isolate).undefined_value();
31 : }
32 :
33 :
34 811 : RUNTIME_FUNCTION(Runtime_SetShrink) {
35 : HandleScope scope(isolate);
36 : DCHECK_EQ(1, args.length());
37 1622 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
38 1622 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
39 811 : table = OrderedHashSet::Shrink(isolate, table);
40 1622 : holder->set_table(*table);
41 811 : return ReadOnlyRoots(isolate).undefined_value();
42 : }
43 :
44 161053 : RUNTIME_FUNCTION(Runtime_MapShrink) {
45 161053 : HandleScope scope(isolate);
46 : DCHECK_EQ(1, args.length());
47 322106 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
48 322106 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
49 161053 : table = OrderedHashMap::Shrink(isolate, table);
50 322106 : holder->set_table(*table);
51 161053 : return ReadOnlyRoots(isolate).undefined_value();
52 : }
53 :
54 3783 : RUNTIME_FUNCTION(Runtime_MapGrow) {
55 3783 : HandleScope scope(isolate);
56 : DCHECK_EQ(1, args.length());
57 7566 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
58 7566 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
59 3783 : table = OrderedHashMap::EnsureGrowable(isolate, table);
60 7566 : holder->set_table(*table);
61 3783 : return ReadOnlyRoots(isolate).undefined_value();
62 : }
63 :
64 0 : RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
65 0 : HandleScope scope(isolate);
66 : DCHECK_EQ(3, args.length());
67 0 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
68 0 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
69 0 : CONVERT_SMI_ARG_CHECKED(hash, 2)
70 :
71 : #ifdef DEBUG
72 : DCHECK(key->IsJSReceiver());
73 : DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key));
74 : Handle<EphemeronHashTable> table(
75 : EphemeronHashTable::cast(weak_collection->table()), isolate);
76 : // Should only be called when shrinking the table is necessary. See
77 : // HashTable::Shrink().
78 : DCHECK(table->NumberOfElements() - 1 <= (table->Capacity() >> 2) &&
79 : table->NumberOfElements() - 1 >= 16);
80 : #endif
81 :
82 0 : bool was_present = JSWeakCollection::Delete(weak_collection, key, hash);
83 0 : return isolate->heap()->ToBoolean(was_present);
84 : }
85 :
86 312 : RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
87 312 : HandleScope scope(isolate);
88 : DCHECK_EQ(4, args.length());
89 624 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
90 312 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
91 312 : CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
92 624 : CONVERT_SMI_ARG_CHECKED(hash, 3)
93 :
94 : #ifdef DEBUG
95 : DCHECK(key->IsJSReceiver());
96 : DCHECK(EphemeronHashTableShape::IsLive(ReadOnlyRoots(isolate), *key));
97 : Handle<EphemeronHashTable> table(
98 : EphemeronHashTable::cast(weak_collection->table()), isolate);
99 : // Should only be called when rehashing or resizing the table is necessary.
100 : // See EphemeronHashTable::Put() and HashTable::HasSufficientCapacityToAdd().
101 : DCHECK((table->NumberOfDeletedElements() << 1) > table->NumberOfElements() ||
102 : !table->HasSufficientCapacityToAdd(1));
103 : #endif
104 :
105 312 : JSWeakCollection::Set(weak_collection, key, value, hash);
106 312 : return *weak_collection;
107 : }
108 :
109 : } // namespace internal
110 178779 : } // namespace v8
|