Skip to content

Commit 8162090

Browse files
jakobkummerowCommit Bot
authored andcommitted
[ubsan] Port SharedFunctionInfo to the new design
Bug: v8:3770 Change-Id: If405611d359d29ae1958beebd9202e068434a621 Reviewed-on: https://chromium-review.googlesource.com/c/1350286 Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#57918}
1 parent 9436e8a commit 8162090

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+310
-301
lines changed

src/api.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,7 @@ StartupData SnapshotCreator::CreateBlob(
756756
i::HeapIterator heap_iterator(isolate->heap());
757757
while (i::HeapObject* current_obj = heap_iterator.next()) {
758758
if (current_obj->IsSharedFunctionInfo()) {
759-
i::SharedFunctionInfo* shared =
760-
i::SharedFunctionInfo::cast(current_obj);
759+
i::SharedFunctionInfo shared = i::SharedFunctionInfo::cast(current_obj);
761760
if (shared->CanDiscardCompiled()) {
762761
sfis_to_clear.emplace_back(shared, isolate);
763762
}
@@ -2143,7 +2142,7 @@ Local<PrimitiveArray> ScriptOrModule::GetHostDefinedOptions() {
21432142

21442143
Local<UnboundScript> Script::GetUnboundScript() {
21452144
i::Handle<i::Object> obj = Utils::OpenHandle(this);
2146-
i::SharedFunctionInfo* sfi = i::JSFunction::cast(*obj)->shared();
2145+
i::SharedFunctionInfo sfi = i::JSFunction::cast(*obj)->shared();
21472146
i::Isolate* isolate = sfi->GetIsolate();
21482147
return ToApiHandle<UnboundScript>(i::handle(sfi, isolate));
21492148
}
@@ -9578,7 +9577,8 @@ void debug::ResetBlackboxedStateCache(Isolate* v8_isolate,
95789577
i::DisallowHeapAllocation no_gc;
95799578
i::SharedFunctionInfo::ScriptIterator iter(isolate,
95809579
*Utils::OpenHandle(*script));
9581-
while (i::SharedFunctionInfo* info = iter.Next()) {
9580+
for (i::SharedFunctionInfo info = iter.Next(); !info.is_null();
9581+
info = iter.Next()) {
95829582
if (info->HasDebugInfo()) {
95839583
info->GetDebugInfo()->set_computed_debug_is_blackboxed(false);
95849584
}

src/asmjs/asm-js.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,20 @@ bool AreStdlibMembersValid(Isolate* isolate, Handle<JSReceiver> stdlib,
6363
Handle<Object> value = JSReceiver::GetDataProperty(stdlib, name);
6464
if (!value->IsNaN()) return false;
6565
}
66-
#define STDLIB_MATH_FUNC(fname, FName, ignore1, ignore2) \
67-
if (members.Contains(wasm::AsmJsParser::StandardMember::kMath##FName)) { \
68-
members.Remove(wasm::AsmJsParser::StandardMember::kMath##FName); \
69-
Handle<Name> name(isolate->factory()->InternalizeOneByteString( \
70-
STATIC_CHAR_VECTOR(#fname))); \
71-
Handle<Object> value = StdlibMathMember(isolate, stdlib, name); \
72-
if (!value->IsJSFunction()) return false; \
73-
SharedFunctionInfo* shared = Handle<JSFunction>::cast(value)->shared(); \
74-
if (!shared->HasBuiltinId() || \
75-
shared->builtin_id() != Builtins::kMath##FName) { \
76-
return false; \
77-
} \
78-
DCHECK_EQ(shared->GetCode(), \
79-
isolate->builtins()->builtin(Builtins::kMath##FName)); \
66+
#define STDLIB_MATH_FUNC(fname, FName, ignore1, ignore2) \
67+
if (members.Contains(wasm::AsmJsParser::StandardMember::kMath##FName)) { \
68+
members.Remove(wasm::AsmJsParser::StandardMember::kMath##FName); \
69+
Handle<Name> name(isolate->factory()->InternalizeOneByteString( \
70+
STATIC_CHAR_VECTOR(#fname))); \
71+
Handle<Object> value = StdlibMathMember(isolate, stdlib, name); \
72+
if (!value->IsJSFunction()) return false; \
73+
SharedFunctionInfo shared = Handle<JSFunction>::cast(value)->shared(); \
74+
if (!shared->HasBuiltinId() || \
75+
shared->builtin_id() != Builtins::kMath##FName) { \
76+
return false; \
77+
} \
78+
DCHECK_EQ(shared->GetCode(), \
79+
isolate->builtins()->builtin(Builtins::kMath##FName)); \
8080
}
8181
STDLIB_MATH_FUNCTION_LIST(STDLIB_MATH_FUNC)
8282
#undef STDLIB_MATH_FUNC

src/code-events.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "src/globals.h"
1212
#include "src/objects/code.h"
1313
#include "src/objects/name.h"
14+
#include "src/objects/shared-function-info.h"
1415
#include "src/objects/string.h"
1516
#include "src/vector.h"
1617

@@ -76,10 +77,10 @@ class CodeEventListener {
7677
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
7778
Name name) = 0;
7879
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
79-
SharedFunctionInfo* shared, Name source) = 0;
80+
SharedFunctionInfo shared, Name source) = 0;
8081
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
81-
SharedFunctionInfo* shared, Name source,
82-
int line, int column) = 0;
82+
SharedFunctionInfo shared, Name source, int line,
83+
int column) = 0;
8384
virtual void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
8485
wasm::WasmName name) = 0;
8586
virtual void CallbackEvent(Name name, Address entry_point) = 0;
@@ -90,7 +91,7 @@ class CodeEventListener {
9091
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
9192
virtual void CodeMovingGCEvent() = 0;
9293
virtual void CodeDisableOptEvent(AbstractCode code,
93-
SharedFunctionInfo* shared) = 0;
94+
SharedFunctionInfo shared) = 0;
9495
virtual void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,
9596
int fp_to_sp_delta) = 0;
9697

@@ -132,11 +133,11 @@ class CodeEventDispatcher {
132133
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
133134
}
134135
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
135-
SharedFunctionInfo* shared, Name name) {
136+
SharedFunctionInfo shared, Name name) {
136137
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, shared, name));
137138
}
138139
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
139-
SharedFunctionInfo* shared, Name source, int line,
140+
SharedFunctionInfo shared, Name source, int line,
140141
int column) {
141142
CODE_EVENT_DISPATCH(
142143
CodeCreateEvent(tag, code, shared, source, line, column));
@@ -164,7 +165,7 @@ class CodeEventDispatcher {
164165
CODE_EVENT_DISPATCH(SharedFunctionInfoMoveEvent(from, to));
165166
}
166167
void CodeMovingGCEvent() { CODE_EVENT_DISPATCH(CodeMovingGCEvent()); }
167-
void CodeDisableOptEvent(AbstractCode code, SharedFunctionInfo* shared) {
168+
void CodeDisableOptEvent(AbstractCode code, SharedFunctionInfo shared) {
168169
CODE_EVENT_DISPATCH(CodeDisableOptEvent(code, shared));
169170
}
170171
void CodeDeoptEvent(Code code, DeoptimizeKind kind, Address pc,

src/compiler-dispatcher/compiler-dispatcher.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ bool CompilerDispatcher::IsEnqueued(JobId job_id) const {
9898
}
9999

100100
void CompilerDispatcher::RegisterSharedFunctionInfo(
101-
JobId job_id, SharedFunctionInfo* function) {
101+
JobId job_id, SharedFunctionInfo function) {
102102
DCHECK_NE(jobs_.find(job_id), jobs_.end());
103103

104104
if (trace_compiler_dispatcher_) {
@@ -108,8 +108,8 @@ void CompilerDispatcher::RegisterSharedFunctionInfo(
108108
}
109109

110110
// Make a global handle to the function.
111-
Handle<SharedFunctionInfo> function_handle =
112-
isolate_->global_handles()->Create(function);
111+
Handle<SharedFunctionInfo> function_handle = Handle<SharedFunctionInfo>::cast(
112+
isolate_->global_handles()->Create(function));
113113

114114
// Register mapping.
115115
auto job_it = jobs_.find(job_id);

src/compiler-dispatcher/compiler-dispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class V8_EXPORT_PRIVATE CompilerDispatcher {
8989
const FunctionLiteral* function_literal);
9090

9191
// Registers the given |function| with the compilation job |job_id|.
92-
void RegisterSharedFunctionInfo(JobId job_id, SharedFunctionInfo* function);
92+
void RegisterSharedFunctionInfo(JobId job_id, SharedFunctionInfo function);
9393

9494
// Returns true if there is a pending job with the given id.
9595
bool IsEnqueued(JobId job_id) const;

src/compiler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
18331833
ASSIGN_RETURN_ON_EXCEPTION(isolate, top_level, maybe_result, JSFunction);
18341834

18351835
SharedFunctionInfo::ScriptIterator infos(isolate, *script);
1836-
while (SharedFunctionInfo* info = infos.Next()) {
1836+
for (SharedFunctionInfo info = infos.Next(); !info.is_null();
1837+
info = infos.Next()) {
18371838
if (info->is_wrapped()) {
18381839
wrapped = Handle<SharedFunctionInfo>(info, isolate);
18391840
break;

src/compiler/linkage.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ CallDescriptor* Linkage::ComputeIncoming(Zone* zone,
145145
if (!info->closure().is_null()) {
146146
// If we are compiling a JS function, use a JS call descriptor,
147147
// plus the receiver.
148-
SharedFunctionInfo* shared = info->closure()->shared();
148+
SharedFunctionInfo shared = info->closure()->shared();
149149
return GetJSCallDescriptor(zone, info->is_osr(),
150150
1 + shared->internal_formal_parameter_count(),
151151
CallDescriptor::kCanUseRoots);

src/compiler/wasm-compiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5092,7 +5092,7 @@ WasmImportCallKind GetWasmImportCallKind(Handle<JSReceiver> target,
50925092
// and whether it has a sloppy receiver.
50935093
if (target->IsJSFunction()) {
50945094
Handle<JSFunction> function = Handle<JSFunction>::cast(target);
5095-
SharedFunctionInfo* shared = function->shared();
5095+
SharedFunctionInfo shared = function->shared();
50965096

50975097
// Check for math intrinsics.
50985098
#define COMPARE_SIG_FOR_BUILTIN(name) \

src/debug/debug-coverage.cc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace v8 {
1717
namespace internal {
1818

1919
class SharedToCounterMap
20-
: public base::TemplateHashMapImpl<SharedFunctionInfo*, uint32_t,
20+
: public base::TemplateHashMapImpl<SharedFunctionInfo, uint32_t,
2121
base::KeyEqualityMatcher<void*>,
2222
base::DefaultAllocationPolicy> {
2323
public:
24-
typedef base::TemplateHashMapEntry<SharedFunctionInfo*, uint32_t> Entry;
25-
inline void Add(SharedFunctionInfo* key, uint32_t count) {
24+
typedef base::TemplateHashMapEntry<SharedFunctionInfo, uint32_t> Entry;
25+
inline void Add(SharedFunctionInfo key, uint32_t count) {
2626
Entry* entry = LookupOrInsert(key, Hash(key), []() { return 0; });
2727
uint32_t old_count = entry->value;
2828
if (UINT32_MAX - count < old_count) {
@@ -32,28 +32,28 @@ class SharedToCounterMap
3232
}
3333
}
3434

35-
inline uint32_t Get(SharedFunctionInfo* key) {
35+
inline uint32_t Get(SharedFunctionInfo key) {
3636
Entry* entry = Lookup(key, Hash(key));
3737
if (entry == nullptr) return 0;
3838
return entry->value;
3939
}
4040

4141
private:
42-
static uint32_t Hash(SharedFunctionInfo* key) {
43-
return static_cast<uint32_t>(reinterpret_cast<intptr_t>(key));
42+
static uint32_t Hash(SharedFunctionInfo key) {
43+
return static_cast<uint32_t>(key.ptr());
4444
}
4545

4646
DisallowHeapAllocation no_gc;
4747
};
4848

4949
namespace {
50-
int StartPosition(SharedFunctionInfo* info) {
50+
int StartPosition(SharedFunctionInfo info) {
5151
int start = info->function_token_position();
5252
if (start == kNoSourcePosition) start = info->StartPosition();
5353
return start;
5454
}
5555

56-
bool CompareSharedFunctionInfo(SharedFunctionInfo* a, SharedFunctionInfo* b) {
56+
bool CompareSharedFunctionInfo(SharedFunctionInfo a, SharedFunctionInfo b) {
5757
int a_start = StartPosition(a);
5858
int b_start = StartPosition(b);
5959
if (a_start == b_start) return a->EndPosition() > b->EndPosition();
@@ -72,7 +72,7 @@ void SortBlockData(std::vector<CoverageBlock>& v) {
7272
std::sort(v.begin(), v.end(), CompareCoverageBlock);
7373
}
7474

75-
std::vector<CoverageBlock> GetSortedBlockData(SharedFunctionInfo* shared) {
75+
std::vector<CoverageBlock> GetSortedBlockData(SharedFunctionInfo shared) {
7676
DCHECK(shared->HasCoverageInfo());
7777

7878
CoverageInfo coverage_info =
@@ -383,7 +383,7 @@ void ClampToBinary(CoverageFunction* function) {
383383
}
384384
}
385385

386-
void ResetAllBlockCounts(SharedFunctionInfo* shared) {
386+
void ResetAllBlockCounts(SharedFunctionInfo shared) {
387387
DCHECK(shared->HasCoverageInfo());
388388

389389
CoverageInfo coverage_info =
@@ -414,7 +414,7 @@ bool IsBinaryMode(debug::Coverage::Mode mode) {
414414
}
415415
}
416416

417-
void CollectBlockCoverage(CoverageFunction* function, SharedFunctionInfo* info,
417+
void CollectBlockCoverage(CoverageFunction* function, SharedFunctionInfo info,
418418
debug::Coverage::Mode mode) {
419419
DCHECK(IsBlockMode(mode));
420420

@@ -500,7 +500,7 @@ std::unique_ptr<Coverage> Coverage::Collect(
500500
isolate->factory()->feedback_vectors_for_profiling_tools());
501501
for (int i = 0; i < list->Length(); i++) {
502502
FeedbackVector* vector = FeedbackVector::cast(list->Get(i));
503-
SharedFunctionInfo* shared = vector->shared_function_info();
503+
SharedFunctionInfo shared = vector->shared_function_info();
504504
DCHECK(shared->IsSubjectToDebugging());
505505
uint32_t count = static_cast<uint32_t>(vector->invocation_count());
506506
if (reset_count) vector->clear_invocation_count();
@@ -517,7 +517,7 @@ std::unique_ptr<Coverage> Coverage::Collect(
517517
while (HeapObject* current_obj = heap_iterator.next()) {
518518
if (!current_obj->IsFeedbackVector()) continue;
519519
FeedbackVector* vector = FeedbackVector::cast(current_obj);
520-
SharedFunctionInfo* shared = vector->shared_function_info();
520+
SharedFunctionInfo shared = vector->shared_function_info();
521521
if (!shared->IsSubjectToDebugging()) continue;
522522
uint32_t count = static_cast<uint32_t>(vector->invocation_count());
523523
counter_map.Add(shared, count);
@@ -538,12 +538,13 @@ std::unique_ptr<Coverage> Coverage::Collect(
538538
result->emplace_back(script_handle);
539539
std::vector<CoverageFunction>* functions = &result->back().functions;
540540

541-
std::vector<SharedFunctionInfo*> sorted;
541+
std::vector<SharedFunctionInfo> sorted;
542542

543543
{
544544
// Sort functions by start position, from outer to inner functions.
545545
SharedFunctionInfo::ScriptIterator infos(isolate, *script_handle);
546-
while (SharedFunctionInfo* info = infos.Next()) {
546+
for (SharedFunctionInfo info = infos.Next(); !info.is_null();
547+
info = infos.Next()) {
547548
sorted.push_back(info);
548549
}
549550
std::sort(sorted.begin(), sorted.end(), CompareSharedFunctionInfo);
@@ -553,7 +554,7 @@ std::unique_ptr<Coverage> Coverage::Collect(
553554
std::vector<size_t> nesting;
554555

555556
// Use sorted list to reconstruct function nesting.
556-
for (SharedFunctionInfo* info : sorted) {
557+
for (SharedFunctionInfo info : sorted) {
557558
int start = StartPosition(info);
558559
int end = info->EndPosition();
559560
uint32_t count = counter_map.Get(info);
@@ -634,7 +635,7 @@ void Coverage::SelectMode(Isolate* isolate, debug::Coverage::Mode mode) {
634635
// If collecting binary coverage, reset
635636
// SFI::has_reported_binary_coverage to avoid optimizing / inlining
636637
// functions before they have reported coverage.
637-
SharedFunctionInfo* shared = SharedFunctionInfo::cast(o);
638+
SharedFunctionInfo shared = SharedFunctionInfo::cast(o);
638639
shared->set_has_reported_binary_coverage(false);
639640
} else if (o->IsFeedbackVector()) {
640641
// In any case, clear any collected invocation counts.

src/debug/debug-type-profile.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::unique_ptr<TypeProfile> TypeProfile::Collect(Isolate* isolate) {
3838
// the list multiple times.
3939
for (int i = 0; i < list->Length(); i++) {
4040
FeedbackVector* vector = FeedbackVector::cast(list->Get(i));
41-
SharedFunctionInfo* info = vector->shared_function_info();
41+
SharedFunctionInfo info = vector->shared_function_info();
4242
DCHECK(info->IsSubjectToDebugging());
4343

4444
// Match vectors with script.
@@ -87,7 +87,7 @@ void TypeProfile::SelectMode(Isolate* isolate, debug::TypeProfile::Mode mode) {
8787

8888
for (int i = 0; i < list->Length(); i++) {
8989
FeedbackVector* vector = FeedbackVector::cast(list->Get(i));
90-
SharedFunctionInfo* info = vector->shared_function_info();
90+
SharedFunctionInfo info = vector->shared_function_info();
9191
DCHECK(info->IsSubjectToDebugging());
9292
if (info->feedback_metadata()->HasTypeProfileSlot()) {
9393
FeedbackSlot slot = vector->GetTypeProfileSlot();

0 commit comments

Comments
 (0)