-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpanoptichrome_patches.diff
6766 lines (6692 loc) · 228 KB
/
panoptichrome_patches.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/BUILD.gn b/BUILD.gn
index c13cf05..d859545 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -3017,6 +3017,8 @@ v8_header_set("v8_internal_headers") {
"src/common/assert-scope.h",
"src/common/checks.h",
"src/common/code-memory-access-inl.h",
+ "src/commons.cc",
+ "src/commons.h",
"src/common/code-memory-access.h",
"src/common/high-allocation-throughput-scope.h",
"src/common/message-template.h",
@@ -5117,6 +5119,8 @@ v8_source_set("v8_base_without_compiler") {
"src/runtime/runtime-shadow-realm.cc",
"src/runtime/runtime-strings.cc",
"src/runtime/runtime-symbol.cc",
+ "src/runtime/runtime-taint.cc",
+ "src/runtime/runtime-taint.h",
"src/runtime/runtime-temporal.cc",
"src/runtime/runtime-test.cc",
"src/runtime/runtime-trace.cc",
diff --git a/src/builtins/builtins-api.cc b/src/builtins/builtins-api.cc
index 94120f0..f160d7c 100644
--- a/src/builtins/builtins-api.cc
+++ b/src/builtins/builtins-api.cc
@@ -182,7 +182,6 @@ MaybeHandle<Object> Builtins::InvokeApiFunction(
ASSIGN_RETURN_ON_EXCEPTION(
isolate, receiver, Object::ConvertReceiver(isolate, receiver), Object);
}
-
// We assume that all lazy accessor pairs have been instantiated when setting
// a break point on any API function.
DCHECK(!Handle<FunctionTemplateInfo>::cast(function)->BreakAtEntry());
@@ -192,7 +191,7 @@ MaybeHandle<Object> Builtins::InvokeApiFunction(
for (int i = 0; i < argc; ++i) {
argv[i + 1] = args[i]->ptr();
}
-
+
RelocatableArguments arguments(isolate, argv.size(), argv.data());
if (is_construct) {
return HandleApiCallHelper<true>(isolate, new_target, function, receiver,
diff --git a/src/codegen/code-stub-assembler.cc b/src/codegen/code-stub-assembler.cc
index d6f303c..a8213f2 100644
--- a/src/codegen/code-stub-assembler.cc
+++ b/src/codegen/code-stub-assembler.cc
@@ -251,13 +251,13 @@ TNode<Smi> CodeStubAssembler::NoContextConstant() {
return SmiConstant(Context::kNoContext);
}
-#define HEAP_CONSTANT_ACCESSOR(rootIndexName, rootAccessorName, name) \
- TNode<std::remove_pointer<std::remove_reference<decltype( \
- std::declval<Heap>().rootAccessorName())>::type>::type> \
- CodeStubAssembler::name##Constant() { \
- return UncheckedCast<std::remove_pointer<std::remove_reference<decltype( \
- std::declval<Heap>().rootAccessorName())>::type>::type>( \
- LoadRoot(RootIndex::k##rootIndexName)); \
+#define HEAP_CONSTANT_ACCESSOR(rootIndexName, rootAccessorName, name) \
+ TNode<std::remove_pointer<std::remove_reference< \
+ decltype(std::declval<Heap>().rootAccessorName())>::type>::type> \
+ CodeStubAssembler::name##Constant() { \
+ return UncheckedCast<std::remove_pointer<std::remove_reference< \
+ decltype(std::declval<Heap>().rootAccessorName())>::type>::type>( \
+ LoadRoot(RootIndex::k##rootIndexName)); \
}
HEAP_MUTABLE_IMMOVABLE_OBJECT_LIST(HEAP_CONSTANT_ACCESSOR)
#undef HEAP_CONSTANT_ACCESSOR
@@ -7495,36 +7495,37 @@ TNode<String> CodeStubAssembler::StringFromSingleCharCode(TNode<Int32T> code) {
TVARIABLE(String, var_result);
// Check if the {code} is a one-byte char code.
- Label if_codeisonebyte(this), if_codeistwobyte(this, Label::kDeferred),
- if_done(this);
- Branch(Int32LessThanOrEqual(code, Int32Constant(String::kMaxOneByteCharCode)),
- &if_codeisonebyte, &if_codeistwobyte);
- BIND(&if_codeisonebyte);
- {
- // Load the isolate wide single character string cache.
- TNode<FixedArray> cache = SingleCharacterStringTableConstant();
- TNode<IntPtrT> code_index = Signed(ChangeUint32ToWord(code));
-
- TNode<Object> entry = UnsafeLoadFixedArrayElement(cache, code_index);
- CSA_DCHECK(this, Word32BinaryNot(IsUndefined(entry)));
-
- // Return the entry from the {cache}.
- var_result = CAST(entry);
- Goto(&if_done);
- }
+ // Label if_codeisonebyte(this), if_codeistwobyte(this, Label::kDeferred),
+ // if_done(this);
+ // Branch(Int32LessThanOrEqual(code,
+ // Int32Constant(String::kMaxOneByteCharCode)),
+ // &if_codeisonebyte, &if_codeistwobyte);
+ // BIND(&if_codeisonebyte);
+ // {
+ // // Load the isolate wide single character string cache.
+ // TNode<FixedArray> cache = SingleCharacterStringTableConstant();
+ // TNode<IntPtrT> code_index = Signed(ChangeUint32ToWord(code));
+
+ // TNode<Object> entry = UnsafeLoadFixedArrayElement(cache, code_index);
+ // CSA_DCHECK(this, Word32BinaryNot(IsUndefined(entry)));
+
+ // // Return the entry from the {cache}.
+ // var_result = CAST(entry);
+ // Goto(&if_done);
+ // }
- BIND(&if_codeistwobyte);
- {
- // Allocate a new SeqTwoByteString for {code}.
- TNode<String> result = AllocateSeqTwoByteString(1);
- StoreNoWriteBarrier(
- MachineRepresentation::kWord16, result,
- IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), code);
- var_result = result;
- Goto(&if_done);
- }
+ // BIND(&if_codeistwobyte);
+ // {
+ // Allocate a new SeqTwoByteString for {code}.
+ TNode<String> result = AllocateSeqTwoByteString(1);
+ StoreNoWriteBarrier(
+ MachineRepresentation::kWord16, result,
+ IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag), code);
+ var_result = result;
+ // Goto(&if_done);
+ // }
- BIND(&if_done);
+ // BIND(&if_done);
return var_result.value();
}
@@ -11488,21 +11489,21 @@ void CodeStubAssembler::StoreElementTypedArrayBigInt(TNode<RawPtrT> elements,
MachineRepresentation rep = WordT::kMachineRepresentation;
#if defined(V8_TARGET_BIG_ENDIAN)
- if (!Is64()) {
- StoreNoWriteBarrier(rep, elements, offset, var_high.value());
- StoreNoWriteBarrier(rep, elements,
- IntPtrAdd(offset, IntPtrConstant(kSystemPointerSize)),
- var_low.value());
- } else {
- StoreNoWriteBarrier(rep, elements, offset, var_low.value());
- }
-#else
+ if (!Is64()) {
+ StoreNoWriteBarrier(rep, elements, offset, var_high.value());
+ StoreNoWriteBarrier(rep, elements,
+ IntPtrAdd(offset, IntPtrConstant(kSystemPointerSize)),
+ var_low.value());
+ } else {
StoreNoWriteBarrier(rep, elements, offset, var_low.value());
- if (!Is64()) {
- StoreNoWriteBarrier(rep, elements,
- IntPtrAdd(offset, IntPtrConstant(kSystemPointerSize)),
- var_high.value());
- }
+ }
+#else
+ StoreNoWriteBarrier(rep, elements, offset, var_low.value());
+ if (!Is64()) {
+ StoreNoWriteBarrier(rep, elements,
+ IntPtrAdd(offset, IntPtrConstant(kSystemPointerSize)),
+ var_high.value());
+ }
#endif
}
@@ -15656,7 +15657,7 @@ TNode<BoolT> CodeStubAssembler::HasAsyncEventDelegate() {
TNode<Uint32T> CodeStubAssembler::PromiseHookFlags() {
return Load<Uint32T>(ExternalConstant(
- ExternalReference::promise_hook_flags_address(isolate())));
+ ExternalReference::promise_hook_flags_address(isolate())));
}
TNode<BoolT> CodeStubAssembler::IsAnyPromiseHookEnabled(TNode<Uint32T> flags) {
@@ -15677,8 +15678,9 @@ TNode<BoolT> CodeStubAssembler::IsContextPromiseHookEnabled(
}
#endif
-TNode<BoolT> CodeStubAssembler::
- IsIsolatePromiseHookEnabledOrHasAsyncEventDelegate(TNode<Uint32T> flags) {
+TNode<BoolT>
+CodeStubAssembler::IsIsolatePromiseHookEnabledOrHasAsyncEventDelegate(
+ TNode<Uint32T> flags) {
uint32_t mask = Isolate::PromiseHookFields::HasIsolatePromiseHook::kMask |
Isolate::PromiseHookFields::HasAsyncEventDelegate::kMask;
return IsSetWord32(flags, mask);
diff --git a/src/commons.cc b/src/commons.cc
new file mode 100644
index 0000000..e624967
--- /dev/null
+++ b/src/commons.cc
@@ -0,0 +1,267 @@
+#include "src/commons.h"
+
+#include <cstddef>
+#include <iostream>
+
+namespace v8 {
+namespace commons {
+
+void LinkedList::initialize() {
+ fake_head_.prev = fake_tail_.next = NULL;
+ fake_head_.next = &fake_tail_;
+ fake_tail_.prev = &fake_head_;
+ size_ = 0;
+}
+
+void LinkedList::destroy() {
+ ListNode *prev, *cur;
+ for (cur = fake_head_.next; cur != &fake_tail_;) {
+ prev = cur;
+ cur = cur->next;
+ delete prev;
+ }
+ initialize();
+}
+
+LinkedList::LinkedList() { initialize(); }
+
+LinkedList::~LinkedList() { destroy(); }
+
+static void IterateLinkedListCopy(void* key, void* value, void* data) {
+ LinkedList* list = (LinkedList*)data;
+ list->append(key, value);
+}
+
+LinkedList& LinkedList::operator=(const LinkedList& other) {
+ destroy();
+ other.iterate(IterateLinkedListCopy, this);
+ return *this;
+}
+
+LinkedList::LinkedList(LinkedList& other) {
+ initialize();
+ other.iterate(IterateLinkedListCopy, this);
+}
+
+void LinkedList::prepend(void* key, void* value) {
+ ListNode* node = new ListNode();
+ node->key = key;
+ node->value = value;
+
+ node->next = fake_head_.next;
+ node->prev = &fake_head_;
+ fake_head_.next->prev = node;
+ fake_head_.next = node;
+
+ size_ += 1;
+}
+
+void LinkedList::append(void* key, void* value) {
+ ListNode* node = new ListNode();
+ node->key = key;
+ node->value = value;
+
+ node->next = &fake_tail_;
+ node->prev = fake_tail_.prev;
+ fake_tail_.prev->next = node;
+ fake_tail_.prev = node;
+
+ size_ += 1;
+}
+
+void LinkedList::remove(void* key) {
+ ListNode* cur;
+ for (cur = &fake_head_; cur->next != &fake_tail_ && cur->next->key != key;
+ cur = cur->next) {
+ ;
+ }
+ if (cur->next != &fake_tail_) {
+ ListNode* p = cur->next;
+ cur->next = p->next;
+ p->next->prev = cur;
+ delete p;
+ size_ -= 1;
+ }
+}
+
+bool LinkedList::search(void* key) {
+ for (ListNode* cur = fake_head_.next; cur != &fake_tail_; cur = cur->next)
+ if (cur->key == key) return true;
+ return false;
+}
+
+void* LinkedList::get(void* key) {
+ for (ListNode* cur = fake_head_.next; cur != &fake_tail_; cur = cur->next)
+ if (cur->key == key) return cur->value;
+ return NULL;
+}
+
+void LinkedList::iterate(IterateCallback callback, void* data) const {
+ for (ListNode* cur = fake_head_.next; cur != &fake_tail_; cur = cur->next)
+ callback(cur->key, cur->value, data);
+}
+
+bool LinkedList::empty() { return (size_ == 0); }
+
+void* LinkedList::head_key() {
+ if (!empty()) return fake_head_.next->key;
+ return NULL;
+}
+
+void* LinkedList::head_value() {
+ if (!empty()) return fake_head_.next->value;
+ return NULL;
+}
+
+void* LinkedList::tail_key() {
+ if (!empty()) return fake_tail_.prev->key;
+ return NULL;
+}
+
+void* LinkedList::tail_value() {
+ if (!empty()) return fake_tail_.prev->value;
+ return NULL;
+}
+
+void LinkedList::pop_head() {
+ if (!empty()) {
+ ListNode* p = fake_head_.next;
+ fake_head_.next = p->next;
+ p->next->prev = &fake_head_;
+ delete p;
+ size_ -= 1;
+ }
+}
+
+void LinkedList::pop_tail() {
+ if (!empty()) {
+ ListNode* p = fake_tail_.prev;
+ fake_tail_.prev = p->prev;
+ p->prev->next = &fake_tail_;
+ delete p;
+ size_ -= 1;
+ }
+}
+
+void LinkedList::clear() { destroy(); }
+
+HashTable::HashTable() {
+ buckets_ = new LinkedList[kMinCapacity];
+ capacity_ = kMinCapacity;
+ size_ = 0;
+}
+
+HashTable::~HashTable() {
+ delete[] buckets_;
+ buckets_ = NULL;
+ capacity_ = 0;
+ size_ = 0;
+}
+
+int HashTable::hash_pointer(void* ptr, int mod) {
+ unsigned long long hash = reinterpret_cast<unsigned long long>(ptr);
+ hash = ~hash + (hash << 18); // hash = (hash << 18) - hash - 1;
+ hash = hash ^ (hash >> 31);
+ hash = hash * 21; // hash = (hash + (hash << 2)) + (hash << 4);
+ hash = hash ^ (hash >> 11);
+ hash = hash + (hash << 6);
+ hash = hash ^ (hash >> 22);
+ hash = hash % ((unsigned long)mod);
+
+ int temp = int(hash % ((unsigned long)mod));
+
+ CHECK((int)hash >= 0 && (int)hash < mod);
+ return temp;
+}
+
+void HashTable::insert(void* key, void* value) {
+ remove(key); // Overwrite if duplicate key.
+ unsigned long long idx = hash_pointer(key, capacity_);
+ buckets_[idx].append(key, value);
+ size_ += 1;
+ check_load_factor();
+}
+
+void HashTable::remove(void* key) {
+ int idx = hash_pointer(key, capacity_);
+ if (buckets_[idx].search(key)) {
+ buckets_[idx].remove(key);
+ size_ -= 1;
+ check_load_factor();
+ }
+}
+
+bool HashTable::search(void* key) {
+ int idx = hash_pointer(key, capacity_);
+ return buckets_[idx].search(key);
+}
+
+void* HashTable::get(void* key) {
+ int idx = hash_pointer(key, capacity_);
+ return buckets_[idx].get(key);
+}
+
+void HashTable::clear() {
+ delete[] buckets_;
+ buckets_ = new LinkedList[kMinCapacity];
+ capacity_ = kMinCapacity;
+ size_ = 0;
+}
+
+void HashTable::iterate(IterateCallback callback, void* data) {
+ for (int idx = 0; idx < capacity_; idx++) {
+ buckets_[idx].iterate(callback, data);
+ }
+}
+
+bool HashTable::empty() { return (size_ == 0); }
+
+struct ResizeHashTable_Data {
+ LinkedList* new_buckets;
+ int new_capacity;
+};
+
+void HashTable::Iterate_ResizeHashTable(void* key, void* value, void* data) {
+ ResizeHashTable_Data* d = static_cast<ResizeHashTable_Data*>(data);
+ int idx = hash_pointer(key, d->new_capacity);
+ d->new_buckets[idx].append(key, value);
+}
+
+void HashTable::resize_table(int new_capacity) {
+ LinkedList* new_buckets = new LinkedList[new_capacity];
+ ResizeHashTable_Data data = {new_buckets, new_capacity};
+ this->iterate(Iterate_ResizeHashTable, &data);
+ delete[] buckets_;
+ buckets_ = new_buckets;
+ capacity_ = new_capacity;
+}
+
+void HashTable::check_load_factor() {
+ int upper_limit = (capacity_ / 4) * 3;
+ int lower_limit = (capacity_ / 4);
+ if (size_ < lower_limit && capacity_ / 2 >= kMinCapacity)
+ resize_table(capacity_ / 2);
+ else if (size_ > upper_limit)
+ resize_table(capacity_ * 2);
+}
+
+void* HashTable::removeAndReturnFirst() {
+ void* key=NULL;
+
+ if (!empty()) {
+ for (int idx = 0; idx < capacity_; idx++) {
+ if (!buckets_[idx].empty()) {
+ key = buckets_[idx].head_key();
+ buckets_[idx].pop_head();
+ size_ -= 1;
+ check_load_factor();
+ break;
+ }
+ }
+ }
+
+ return key;
+}
+
+} // namespace commons
+} // namespace v8
diff --git a/src/commons.h b/src/commons.h
new file mode 100644
index 0000000..2e11964
--- /dev/null
+++ b/src/commons.h
@@ -0,0 +1,132 @@
+
+#ifndef V8_COMMONS_H_
+#define V8_COMMONS_H_
+
+#include <unordered_set>
+
+#include "json.hpp"
+#include "src/base/logging.h"
+// using Address = uintptr_t;
+namespace v8 {
+namespace commons {
+
+class Properties {
+ public:
+ Properties() {
+ included_properties = nullptr;
+ excluded_properties = nullptr;
+ }
+ std::map<std::string, int>* included_properties;
+ std::map<std::string, int>* excluded_properties;
+ int obj_id;
+};
+
+class ParseInfoAndRCState {
+ public:
+ ParseInfoAndRCState() {
+ parse_info = nullptr;
+ ruc_state = nullptr;
+ }
+
+ ParseInfoAndRCState(void* pi, void* ruc) {
+ parse_info = pi;
+ ruc_state = ruc;
+ }
+
+ void* parse_info; // ParseInfo
+ void* ruc_state; // ReusableUnoptimizedCompileState
+};
+
+typedef void (*IterateCallback)(void* key, void* value, void* data);
+
+// Doubly-linked list.
+class LinkedList {
+ public:
+ LinkedList();
+
+ LinkedList(LinkedList& other);
+
+ ~LinkedList();
+
+ LinkedList& operator=(const LinkedList& other);
+
+ bool empty();
+
+ void prepend(void* key, void* value);
+ void append(void* key, void* value);
+ void remove(void* key);
+ bool search(void* key);
+ void* get(void* key);
+
+ void* head_key();
+ void* head_value();
+ void* tail_key();
+ void* tail_value();
+
+ void pop_head();
+ void pop_tail();
+
+ void clear();
+
+ void iterate(IterateCallback callback, void* data) const;
+
+ int size() { return size_; }
+
+ private:
+ void initialize();
+ void destroy();
+
+ struct ListNode {
+ void* key;
+ void* value;
+ struct ListNode* prev;
+ struct ListNode* next;
+ };
+
+ ListNode fake_head_;
+ ListNode fake_tail_;
+ int size_;
+};
+
+// Hash with chaining.
+class HashTable {
+ public:
+ HashTable();
+
+ ~HashTable();
+
+ bool empty();
+
+ void insert(void* key, void* value);
+ void remove(void* key);
+ bool search(void* key);
+ void* get(void* key);
+
+ void clear();
+
+ void iterate(IterateCallback callback, void* data);
+
+ int size() { return size_; }
+
+ int capacity() { return capacity_; }
+
+ void* removeAndReturnFirst();
+
+ static int hash_pointer(void* ptr, int mod);
+
+ private:
+ static void Iterate_ResizeHashTable(void* key, void* value, void* data);
+ void resize_table(int new_capacity);
+ void check_load_factor();
+
+ static const int kMinCapacity = 8;
+
+ LinkedList* buckets_;
+ int capacity_; // Number of buckets.
+ int size_; // Total number of keys.
+};
+
+} // namespace commons
+} // namespace v8
+
+#endif
\ No newline at end of file
diff --git a/src/compiler/js-call-reducer.cc b/src/compiler/js-call-reducer.cc
index b0c7907..9e6e1e7 100644
--- a/src/compiler/js-call-reducer.cc
+++ b/src/compiler/js-call-reducer.cc
@@ -3821,227 +3821,240 @@ FastApiCallFunctionVector CanOptimizeFastCall(
Reduction JSCallReducer::ReduceCallApiFunction(Node* node,
SharedFunctionInfoRef shared) {
- JSCallNode n(node);
- CallParameters const& p = n.Parameters();
- int const argc = p.arity_without_implicit_args();
- Node* target = n.target();
- Node* global_proxy = jsgraph()->Constant(
- native_context().global_proxy_object(broker()), broker());
- Node* receiver = (p.convert_mode() == ConvertReceiverMode::kNullOrUndefined)
- ? global_proxy
- : n.receiver();
- Node* holder;
- Node* context = n.context();
- Effect effect = n.effect();
- Control control = n.control();
- FrameState frame_state = n.frame_state();
-
- if (!shared.function_template_info(broker()).has_value()) {
- TRACE_BROKER_MISSING(
- broker(), "FunctionTemplateInfo for function with SFI " << shared);
- return NoChange();
- }
-
- // See if we can optimize this API call to {shared}.
- FunctionTemplateInfoRef function_template_info(
- shared.function_template_info(broker()).value());
-
- if (function_template_info.accept_any_receiver() &&
- function_template_info.is_signature_undefined(broker())) {
- // We might be able to
- // optimize the API call depending on the {function_template_info}.
- // If the API function accepts any kind of {receiver}, we only need to
- // ensure that the {receiver} is actually a JSReceiver at this point,
- // and also pass that as the {holder}. There are two independent bits
- // here:
- //
- // a. When the "accept any receiver" bit is set, it means we don't
- // need to perform access checks, even if the {receiver}'s map
- // has the "needs access check" bit set.
- // b. When the {function_template_info} has no signature, we don't
- // need to do the compatible receiver check, since all receivers
- // are considered compatible at that point, and the {receiver}
- // will be pass as the {holder}.
- //
- receiver = holder = effect =
- graph()->NewNode(simplified()->ConvertReceiver(p.convert_mode()),
- receiver, global_proxy, effect, control);
- } else {
- // Try to infer the {receiver} maps from the graph.
- MapInference inference(broker(), receiver, effect);
- if (inference.HaveMaps()) {
- ZoneRefSet<Map> const& receiver_maps = inference.GetMaps();
- MapRef first_receiver_map = receiver_maps[0];
-
- // See if we can constant-fold the compatible receiver checks.
- HolderLookupResult api_holder =
- function_template_info.LookupHolderOfExpectedType(broker(),
- first_receiver_map);
- if (api_holder.lookup == CallOptimization::kHolderNotFound) {
- return inference.NoChange();
- }
-
- // Check that all {receiver_maps} are actually JSReceiver maps and
- // that the {function_template_info} accepts them without access
- // checks (even if "access check needed" is set for {receiver}).
- //
- // Note that we don't need to know the concrete {receiver} maps here,
- // meaning it's fine if the {receiver_maps} are unreliable, and we also
- // don't need to install any stability dependencies, since the only
- // relevant information regarding the {receiver} is the Map::constructor
- // field on the root map (which is different from the JavaScript exposed
- // "constructor" property) and that field cannot change.
- //
- // So if we know that {receiver} had a certain constructor at some point
- // in the past (i.e. it had a certain map), then this constructor is going
- // to be the same later, since this information cannot change with map
- // transitions.
- //
- // The same is true for the instance type, e.g. we still know that the
- // instance type is JSObject even if that information is unreliable, and
- // the "access check needed" bit, which also cannot change later.
- CHECK(first_receiver_map.IsJSReceiverMap());
- CHECK(!first_receiver_map.is_access_check_needed() ||
- function_template_info.accept_any_receiver());
-
- for (size_t i = 1; i < receiver_maps.size(); ++i) {
- MapRef receiver_map = receiver_maps[i];
- HolderLookupResult holder_i =
- function_template_info.LookupHolderOfExpectedType(broker(),
- receiver_map);
-
- if (api_holder.lookup != holder_i.lookup) return inference.NoChange();
- DCHECK(holder_i.lookup == CallOptimization::kHolderFound ||
- holder_i.lookup == CallOptimization::kHolderIsReceiver);
- if (holder_i.lookup == CallOptimization::kHolderFound) {
- DCHECK(api_holder.holder.has_value() && holder_i.holder.has_value());
- if (!api_holder.holder->equals(*holder_i.holder)) {
- return inference.NoChange();
- }
- }
-
- CHECK(receiver_map.IsJSReceiverMap());
- CHECK(!receiver_map.is_access_check_needed() ||
- function_template_info.accept_any_receiver());
- }
-
- if (p.speculation_mode() == SpeculationMode::kDisallowSpeculation &&
- !inference.RelyOnMapsViaStability(dependencies())) {
- // We were not able to make the receiver maps reliable without map
- // checks but doing map checks would lead to deopt loops, so give up.
- return inference.NoChange();
- }
+ // JSCallNode n(node);
+ // CallParameters const& p = n.Parameters();
+ // int const argc = p.arity_without_implicit_args();
+ // Node* target = n.target();
+ // Node* global_proxy = jsgraph()->Constant(
+ // native_context().global_proxy_object(broker()), broker());
+ // Node* receiver = (p.convert_mode() ==
+ // ConvertReceiverMode::kNullOrUndefined)
+ // ? global_proxy
+ // : n.receiver();
+ // Node* holder;
+ // Node* context = n.context();
+ // Effect effect = n.effect();
+ // Control control = n.control();
+ // FrameState frame_state = n.frame_state();
+
+ // if (!shared.function_template_info(broker()).has_value()) {
+ // TRACE_BROKER_MISSING(
+ // broker(), "FunctionTemplateInfo for function with SFI " << shared);
+ // return NoChange();
+ // }
+
+ // // See if we can optimize this API call to {shared}.
+ // FunctionTemplateInfoRef function_template_info(
+ // shared.function_template_info(broker()).value());
+
+ // if (function_template_info.accept_any_receiver() &&
+ // function_template_info.is_signature_undefined(broker())) {
+ // // We might be able to
+ // // optimize the API call depending on the {function_template_info}.
+ // // If the API function accepts any kind of {receiver}, we only need to
+ // // ensure that the {receiver} is actually a JSReceiver at this point,
+ // // and also pass that as the {holder}. There are two independent bits
+ // // here:
+ // //
+ // // a. When the "accept any receiver" bit is set, it means we don't
+ // // need to perform access checks, even if the {receiver}'s map
+ // // has the "needs access check" bit set.
+ // // b. When the {function_template_info} has no signature, we don't
+ // // need to do the compatible receiver check, since all receivers
+ // // are considered compatible at that point, and the {receiver}
+ // // will be pass as the {holder}.
+ // //
+ // receiver = holder = effect =
+ // graph()->NewNode(simplified()->ConvertReceiver(p.convert_mode()),
+ // receiver, global_proxy, effect, control);
+ // } else {
+ // // Try to infer the {receiver} maps from the graph.
+ // MapInference inference(broker(), receiver, effect);
+ // if (inference.HaveMaps()) {
+ // ZoneRefSet<Map> const& receiver_maps = inference.GetMaps();
+ // MapRef first_receiver_map = receiver_maps[0];
+
+ // // See if we can constant-fold the compatible receiver checks.
+ // HolderLookupResult api_holder =
+ // function_template_info.LookupHolderOfExpectedType(broker(),
+ // first_receiver_map);
+ // if (api_holder.lookup == CallOptimization::kHolderNotFound) {
+ // return inference.NoChange();
+ // }
- // TODO(neis): The maps were used in a way that does not actually require
- // map checks or stability dependencies.
- inference.RelyOnMapsPreferStability(dependencies(), jsgraph(), &effect,
- control, p.feedback());
+ // // Check that all {receiver_maps} are actually JSReceiver maps and
+ // // that the {function_template_info} accepts them without access
+ // // checks (even if "access check needed" is set for {receiver}).
+ // //
+ // // Note that we don't need to know the concrete {receiver} maps here,
+ // // meaning it's fine if the {receiver_maps} are unreliable, and we also
+ // // don't need to install any stability dependencies, since the only
+ // // relevant information regarding the {receiver} is the
+ // Map::constructor
+ // // field on the root map (which is different from the JavaScript
+ // exposed
+ // // "constructor" property) and that field cannot change.
+ // //
+ // // So if we know that {receiver} had a certain constructor at some
+ // point
+ // // in the past (i.e. it had a certain map), then this constructor is
+ // going
+ // // to be the same later, since this information cannot change with map
+ // // transitions.
+ // //
+ // // The same is true for the instance type, e.g. we still know that the
+ // // instance type is JSObject even if that information is unreliable,
+ // and
+ // // the "access check needed" bit, which also cannot change later.
+ // CHECK(first_receiver_map.IsJSReceiverMap());
+ // CHECK(!first_receiver_map.is_access_check_needed() ||
+ // function_template_info.accept_any_receiver());
+
+ // for (size_t i = 1; i < receiver_maps.size(); ++i) {
+ // MapRef receiver_map = receiver_maps[i];
+ // HolderLookupResult holder_i =
+ // function_template_info.LookupHolderOfExpectedType(broker(),
+ // receiver_map);
+
+ // if (api_holder.lookup != holder_i.lookup) return
+ // inference.NoChange(); DCHECK(holder_i.lookup ==
+ // CallOptimization::kHolderFound ||
+ // holder_i.lookup == CallOptimization::kHolderIsReceiver);
+ // if (holder_i.lookup == CallOptimization::kHolderFound) {
+ // DCHECK(api_holder.holder.has_value() &&
+ // holder_i.holder.has_value()); if
+ // (!api_holder.holder->equals(*holder_i.holder)) {
+ // return inference.NoChange();
+ // }
+ // }
+
+ // CHECK(receiver_map.IsJSReceiverMap());
+ // CHECK(!receiver_map.is_access_check_needed() ||
+ // function_template_info.accept_any_receiver());
+ // }
- // Determine the appropriate holder for the {lookup}.
- holder = api_holder.lookup == CallOptimization::kHolderFound
- ? jsgraph()->Constant(*api_holder.holder, broker())
- : receiver;
- } else {
- // We don't have enough information to eliminate the access check
- // and/or the compatible receiver check, so use the generic builtin
- // that does those checks dynamically. This is still significantly
- // faster than the generic call sequence.
- Builtin builtin_name;
- if (function_template_info.accept_any_receiver()) {
- builtin_name = Builtin::kCallFunctionTemplate_CheckCompatibleReceiver;
- } else if (function_template_info.is_signature_undefined(broker())) {
- builtin_name = Builtin::kCallFunctionTemplate_CheckAccess;
- } else {
- builtin_name =
- Builtin::kCallFunctionTemplate_CheckAccessAndCompatibleReceiver;
- }
+ // if (p.speculation_mode() == SpeculationMode::kDisallowSpeculation &&
+ // !inference.RelyOnMapsViaStability(dependencies())) {
+ // // We were not able to make the receiver maps reliable without map
+ // // checks but doing map checks would lead to deopt loops, so give up.
+ // return inference.NoChange();
+ // }
- // The CallFunctionTemplate builtin requires the {receiver} to be
- // an actual JSReceiver, so make sure we do the proper conversion
- // first if necessary.
- receiver = holder = effect =
- graph()->NewNode(simplified()->ConvertReceiver(p.convert_mode()),
- receiver, global_proxy, effect, control);
-
- Callable callable = Builtins::CallableFor(isolate(), builtin_name);
- auto call_descriptor = Linkage::GetStubCallDescriptor(
- graph()->zone(), callable.descriptor(),
- argc + 1 /* implicit receiver */, CallDescriptor::kNeedsFrameState);
- node->RemoveInput(n.FeedbackVectorIndex());
- node->InsertInput(graph()->zone(), 0,
- jsgraph()->HeapConstant(callable.code()));
- node->ReplaceInput(1,
- jsgraph()->Constant(function_template_info, broker()));
- node->InsertInput(graph()->zone(), 2,
- jsgraph()->Constant(JSParameterCount(argc)));
- node->ReplaceInput(3, receiver); // Update receiver input.
- node->ReplaceInput(6 + argc, effect); // Update effect input.
- NodeProperties::ChangeOp(node, common()->Call(call_descriptor));
- return Changed(node);
- }
- }
+ // // TODO(neis): The maps were used in a way that does not actually
+ // require
+ // // map checks or stability dependencies.
+ // inference.RelyOnMapsPreferStability(dependencies(), jsgraph(), &effect,
+ // control, p.feedback());
+
+ // // Determine the appropriate holder for the {lookup}.
+ // holder = api_holder.lookup == CallOptimization::kHolderFound
+ // ? jsgraph()->Constant(*api_holder.holder, broker())
+ // : receiver;
+ // } else {
+ // // We don't have enough information to eliminate the access check
+ // // and/or the compatible receiver check, so use the generic builtin
+ // // that does those checks dynamically. This is still significantly
+ // // faster than the generic call sequence.
+ // Builtin builtin_name;
+ // if (function_template_info.accept_any_receiver()) {
+ // builtin_name =
+ // Builtin::kCallFunctionTemplate_CheckCompatibleReceiver;
+ // } else if (function_template_info.is_signature_undefined(broker())) {
+ // builtin_name = Builtin::kCallFunctionTemplate_CheckAccess;
+ // } else {
+ // builtin_name =
+ // Builtin::kCallFunctionTemplate_CheckAccessAndCompatibleReceiver;
+ // }
- // TODO(turbofan): Consider introducing a JSCallApiCallback operator for
- // this and lower it during JSGenericLowering, and unify this with the
- // JSNativeContextSpecialization::InlineApiCall method a bit.
- if (!function_template_info.call_code(broker()).has_value()) {
- TRACE_BROKER_MISSING(broker(), "call code for function template info "
- << function_template_info);
+ // // The CallFunctionTemplate builtin requires the {receiver} to be
+ // // an actual JSReceiver, so make sure we do the proper conversion
+ // // first if necessary.
+ // receiver = holder = effect =
+ // graph()->NewNode(simplified()->ConvertReceiver(p.convert_mode()),
+ // receiver, global_proxy, effect, control);
+
+ // Callable callable = Builtins::CallableFor(isolate(), builtin_name);
+ // auto call_descriptor = Linkage::GetStubCallDescriptor(
+ // graph()->zone(), callable.descriptor(),
+ // argc + 1 /* implicit receiver */,
+ // CallDescriptor::kNeedsFrameState);
+ // node->RemoveInput(n.FeedbackVectorIndex());
+ // node->InsertInput(graph()->zone(), 0,
+ // jsgraph()->HeapConstant(callable.code()));
+ // node->ReplaceInput(1,
+ // jsgraph()->Constant(function_template_info,
+ // broker()));
+ // node->InsertInput(graph()->zone(), 2,
+ // jsgraph()->Constant(JSParameterCount(argc)));
+ // node->ReplaceInput(3, receiver); // Update receiver input.
+ // node->ReplaceInput(6 + argc, effect); // Update effect input.
+ // NodeProperties::ChangeOp(node, common()->Call(call_descriptor));
+ // return Changed(node);
+ // }
+ // }
+
+ // // TODO(turbofan): Consider introducing a JSCallApiCallback operator for
+ // // this and lower it during JSGenericLowering, and unify this with the
+ // // JSNativeContextSpecialization::InlineApiCall method a bit.
+ // if (!function_template_info.call_code(broker()).has_value()) {
+ // TRACE_BROKER_MISSING(broker(), "call code for function template info "
+ // << function_template_info);
return NoChange();
- }
-
- // Handles overloaded functions.
-
- FastApiCallFunctionVector c_candidate_functions = CanOptimizeFastCall(
- broker(), graph()->zone(), function_template_info, argc);
- DCHECK_LE(c_candidate_functions.size(), 2);
-
- // TODO(v8:13600): Support exception handling for FastApiCall nodes.
- if (!c_candidate_functions.empty() &&
- !NodeProperties::IsExceptionalCall(node)) {
- FastApiCallReducerAssembler a(this, node, function_template_info,
- c_candidate_functions, receiver, holder,
- shared, target, argc, effect);
- Node* fast_call_subgraph = a.ReduceFastApiCall();
- ReplaceWithSubgraph(&a, fast_call_subgraph);
-
- return Replace(fast_call_subgraph);
- }
-
- // Slow call
-
- CallHandlerInfoRef call_handler_info =
- *function_template_info.call_code(broker());
- Callable call_api_callback = Builtins::CallableFor(
- isolate(), call_handler_info.object()->IsSideEffectCallHandlerInfo()
- ? Builtin::kCallApiCallbackWithSideEffects
- : Builtin::kCallApiCallbackNoSideEffects);
- CallInterfaceDescriptor cid = call_api_callback.descriptor();
- auto call_descriptor =
- Linkage::GetStubCallDescriptor(graph()->zone(), cid, argc + 1 /*
- implicit receiver */, CallDescriptor::kNeedsFrameState);
- ApiFunction api_function(call_handler_info.callback());
- ExternalReference function_reference = ExternalReference::Create(
- &api_function, ExternalReference::DIRECT_API_CALL);
-
- Node* continuation_frame_state = CreateGenericLazyDeoptContinuationFrameState(
- jsgraph(), shared, target, context, receiver, frame_state);
-
- node->RemoveInput(n.FeedbackVectorIndex());
- node->InsertInput(graph()->zone(), 0,
- jsgraph()->HeapConstant(call_api_callback.code()));
- node->ReplaceInput(1, jsgraph()->ExternalConstant(function_reference));
- node->InsertInput(graph()->zone(), 2, jsgraph()->Constant(argc));
- node->InsertInput(
- graph()->zone(), 3,
- jsgraph()->Constant(call_handler_info.data(broker()), broker()));
- node->InsertInput(graph()->zone(), 4, holder);