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 20 : RUNTIME_FUNCTION(Runtime_TheHole) {
18 : SealHandleScope shs(isolate);
19 : DCHECK_EQ(0, args.length());
20 : return ReadOnlyRoots(isolate).the_hole_value();
21 : }
22 :
23 334430 : RUNTIME_FUNCTION(Runtime_SetGrow) {
24 : HandleScope scope(isolate);
25 : DCHECK_EQ(1, args.length());
26 167215 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
27 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
28 167215 : table = OrderedHashSet::EnsureGrowable(isolate, table);
29 334430 : holder->set_table(*table);
30 : return ReadOnlyRoots(isolate).undefined_value();
31 : }
32 :
33 :
34 1622 : RUNTIME_FUNCTION(Runtime_SetShrink) {
35 : HandleScope scope(isolate);
36 : DCHECK_EQ(1, args.length());
37 811 : CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
38 : Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()), isolate);
39 811 : table = OrderedHashSet::Shrink(isolate, table);
40 1622 : holder->set_table(*table);
41 : return ReadOnlyRoots(isolate).undefined_value();
42 : }
43 :
44 293936 : RUNTIME_FUNCTION(Runtime_MapShrink) {
45 : HandleScope scope(isolate);
46 : DCHECK_EQ(1, args.length());
47 146968 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
48 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
49 146968 : table = OrderedHashMap::Shrink(isolate, table);
50 293936 : holder->set_table(*table);
51 : return ReadOnlyRoots(isolate).undefined_value();
52 : }
53 :
54 7814 : RUNTIME_FUNCTION(Runtime_MapGrow) {
55 : HandleScope scope(isolate);
56 : DCHECK_EQ(1, args.length());
57 3907 : CONVERT_ARG_HANDLE_CHECKED(JSMap, holder, 0);
58 : Handle<OrderedHashMap> table(OrderedHashMap::cast(holder->table()), isolate);
59 3907 : table = OrderedHashMap::EnsureGrowable(isolate, table);
60 7814 : holder->set_table(*table);
61 : return ReadOnlyRoots(isolate).undefined_value();
62 : }
63 :
64 0 : RUNTIME_FUNCTION(Runtime_WeakCollectionDelete) {
65 : HandleScope scope(isolate);
66 : DCHECK_EQ(3, args.length());
67 0 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
68 : 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 : return isolate->heap()->ToBoolean(was_present);
84 : }
85 :
86 624 : RUNTIME_FUNCTION(Runtime_WeakCollectionSet) {
87 : HandleScope scope(isolate);
88 : DCHECK_EQ(4, args.length());
89 312 : CONVERT_ARG_HANDLE_CHECKED(JSWeakCollection, weak_collection, 0);
90 : CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
91 : CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
92 312 : 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 : return *weak_collection;
107 : }
108 :
109 : } // namespace internal
110 121996 : } // namespace v8
|