Skip to content

Commit 3dd5c6f

Browse files
danelphickCommit Bot
authored andcommitted
[string] deprecate String::Utf8Length
Deprecate String::Utf8Length in favor of a new, similar function that takes the Isolate used for the String::Flatten call as an argument. BUG: v8:7786 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng Change-Id: Icaf04b272679fd853e9cdbe6c7088f63e9aacb95 Reviewed-on: https://chromium-review.googlesource.com/1124724 Commit-Queue: Dan Elphick <[email protected]> Reviewed-by: Yang Guo <[email protected]> Reviewed-by: Dan Elphick <[email protected]> Cr-Commit-Position: refs/heads/master@{#54476}
1 parent 804a693 commit 3dd5c6f

13 files changed

Lines changed: 69 additions & 43 deletions

File tree

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Teddy Katz <[email protected]>
150150
Tiancheng "Timothy" Gu <[email protected]>
151151
Tobias Burnus <[email protected]>
152152
Tobias Nießen <[email protected]>
153+
Ujjwal Sharma <[email protected]>
153154
Victor Costan <[email protected]>
154155
Vlad Burlik <[email protected]>
155156
Vladimir Krivosheev <[email protected]>

include/v8.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,9 @@ class V8_EXPORT String : public Name {
26992699
* Returns the number of bytes in the UTF-8 encoded
27002700
* representation of this string.
27012701
*/
2702-
int Utf8Length() const;
2702+
V8_DEPRECATE_SOON("Use Isolate version instead", int Utf8Length() const);
2703+
2704+
int Utf8Length(Isolate* isolate) const;
27032705

27042706
/**
27052707
* Returns whether this string is known to contain only one byte data,
@@ -6986,6 +6988,8 @@ struct JitCodeEvent {
69866988
// New location of instructions. Only valid for CODE_MOVED.
69876989
void* new_code_start;
69886990
};
6991+
6992+
Isolate* isolate;
69896993
};
69906994

69916995
/**

src/api.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5602,10 +5602,14 @@ bool String::ContainsOnlyOneByte() const {
56025602
return helper.Check(*str);
56035603
}
56045604

5605-
// TODO(v8:7786): Deprecate this function and pass the isolate in instead.
56065605
int String::Utf8Length() const {
5606+
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
5607+
return Utf8Length(reinterpret_cast<Isolate*>(isolate));
5608+
}
5609+
5610+
int String::Utf8Length(Isolate* isolate) const {
56075611
i::Handle<i::String> str = Utils::OpenHandle(this);
5608-
str = i::String::Flatten(str->GetIsolate(), str);
5612+
str = i::String::Flatten(reinterpret_cast<i::Isolate*>(isolate), str);
56095613
int length = str->length();
56105614
if (length == 0) return 0;
56115615
i::DisallowHeapAllocation no_gc;
@@ -5627,7 +5631,6 @@ int String::Utf8Length() const {
56275631
return utf8_length;
56285632
}
56295633

5630-
56315634
class Utf8WriterVisitor {
56325635
public:
56335636
Utf8WriterVisitor(
@@ -5846,7 +5849,7 @@ int String::WriteUtf8(Isolate* v8_isolate, char* buffer, int capacity,
58465849
if (success) return writer.CompleteWrite(write_null, nchars_ref);
58475850
} else if (capacity >= string_length) {
58485851
// First check that the buffer is large enough.
5849-
int utf8_bytes = Utf8Length();
5852+
int utf8_bytes = Utf8Length(reinterpret_cast<Isolate*>(isolate));
58505853
if (utf8_bytes <= capacity) {
58515854
// one-byte fast path.
58525855
if (utf8_bytes == string_length) {
@@ -9235,7 +9238,7 @@ String::Utf8Value::Utf8Value(v8::Isolate* isolate, v8::Local<v8::Value> obj)
92359238
TryCatch try_catch(isolate);
92369239
Local<String> str;
92379240
if (!obj->ToString(context).ToLocal(&str)) return;
9238-
length_ = str->Utf8Length();
9241+
length_ = str->Utf8Length(isolate);
92399242
str_ = i::NewArray<char>(length_ + 1);
92409243
str->WriteUtf8(str_);
92419244
}

src/d8.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ base::OnceType Shell::quit_once_ = V8_ONCE_INIT;
425425
// Dummy external source stream which returns the whole source in one go.
426426
class DummySourceStream : public v8::ScriptCompiler::ExternalSourceStream {
427427
public:
428-
explicit DummySourceStream(Local<String> source) : done_(false) {
429-
source_length_ = source->Utf8Length();
428+
DummySourceStream(Local<String> source, Isolate* isolate) : done_(false) {
429+
source_length_ = source->Utf8Length(isolate);
430430
source_buffer_.reset(new uint8_t[source_length_]);
431431
source->WriteUtf8(reinterpret_cast<char*>(source_buffer_.get()),
432432
source_length_);
@@ -453,7 +453,7 @@ class BackgroundCompileThread : public base::Thread {
453453
BackgroundCompileThread(Isolate* isolate, Local<String> source)
454454
: base::Thread(GetThreadOptions("BackgroundCompileThread")),
455455
source_(source),
456-
streamed_source_(new DummySourceStream(source),
456+
streamed_source_(new DummySourceStream(source, isolate),
457457
v8::ScriptCompiler::StreamedSource::UTF8),
458458
task_(v8::ScriptCompiler::StartStreamingScript(isolate,
459459
&streamed_source_)) {}

src/log.cc

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ class CodeEventLogger::NameBuffer {
191191
uc16 utf16_buffer[kUtf16BufferSize];
192192
};
193193

194-
195-
CodeEventLogger::CodeEventLogger() : name_buffer_(new NameBuffer) { }
194+
CodeEventLogger::CodeEventLogger(Isolate* isolate)
195+
: isolate_(isolate), name_buffer_(new NameBuffer) {}
196196

197197
CodeEventLogger::~CodeEventLogger() { delete name_buffer_; }
198198

@@ -267,7 +267,7 @@ void CodeEventLogger::RegExpCodeCreateEvent(AbstractCode* code,
267267
// Linux perf tool logging support
268268
class PerfBasicLogger : public CodeEventLogger {
269269
public:
270-
PerfBasicLogger();
270+
explicit PerfBasicLogger(Isolate* isolate);
271271
~PerfBasicLogger() override;
272272

273273
void CodeMoveEvent(AbstractCode* from, Address to) override {}
@@ -293,7 +293,8 @@ const char PerfBasicLogger::kFilenameFormatString[] = "/tmp/perf-%d.map";
293293
// Extra space for the PID in the filename
294294
const int PerfBasicLogger::kFilenameBufferPadding = 16;
295295

296-
PerfBasicLogger::PerfBasicLogger() : perf_output_handle_(nullptr) {
296+
PerfBasicLogger::PerfBasicLogger(Isolate* isolate)
297+
: CodeEventLogger(isolate), perf_output_handle_(nullptr) {
297298
// Open the perf JIT dump file.
298299
int bufferSize = sizeof(kFilenameFormatString) + kFilenameBufferPadding;
299300
ScopedVector<char> perf_dump_name(bufferSize);
@@ -492,7 +493,7 @@ void ExternalCodeEventListener::RegExpCodeCreateEvent(AbstractCode* code,
492493
// Low-level logging support.
493494
class LowLevelLogger : public CodeEventLogger {
494495
public:
495-
explicit LowLevelLogger(const char* file_name);
496+
LowLevelLogger(Isolate* isolate, const char* file_name);
496497
~LowLevelLogger() override;
497498

498499
void CodeMoveEvent(AbstractCode* from, Address to) override;
@@ -546,7 +547,8 @@ class LowLevelLogger : public CodeEventLogger {
546547

547548
const char LowLevelLogger::kLogExt[] = ".ll";
548549

549-
LowLevelLogger::LowLevelLogger(const char* name) : ll_output_handle_(nullptr) {
550+
LowLevelLogger::LowLevelLogger(Isolate* isolate, const char* name)
551+
: CodeEventLogger(isolate), ll_output_handle_(nullptr) {
550552
// Open the low-level log file.
551553
size_t len = strlen(name);
552554
ScopedVector<char> ll_name(static_cast<int>(len + sizeof(kLogExt)));
@@ -637,7 +639,7 @@ void LowLevelLogger::CodeMovingGCEvent() {
637639

638640
class JitLogger : public CodeEventLogger {
639641
public:
640-
explicit JitLogger(JitCodeEventHandler code_event_handler);
642+
JitLogger(Isolate* isolate, JitCodeEventHandler code_event_handler);
641643

642644
void CodeMoveEvent(AbstractCode* from, Address to) override;
643645
void CodeDisableOptEvent(AbstractCode* code,
@@ -659,10 +661,8 @@ class JitLogger : public CodeEventLogger {
659661
base::Mutex logger_mutex_;
660662
};
661663

662-
663-
JitLogger::JitLogger(JitCodeEventHandler code_event_handler)
664-
: code_event_handler_(code_event_handler) {
665-
}
664+
JitLogger::JitLogger(Isolate* isolate, JitCodeEventHandler code_event_handler)
665+
: CodeEventLogger(isolate), code_event_handler_(code_event_handler) {}
666666

667667
void JitLogger::LogRecordedBuffer(AbstractCode* code,
668668
SharedFunctionInfo* shared, const char* name,
@@ -682,6 +682,7 @@ void JitLogger::LogRecordedBuffer(AbstractCode* code,
682682
event.script = ToApiHandle<v8::UnboundScript>(shared_function_handle);
683683
event.name.str = name;
684684
event.name.len = length;
685+
event.isolate = reinterpret_cast<v8::Isolate*>(isolate_);
685686
code_event_handler_(&event);
686687
}
687688

@@ -695,6 +696,7 @@ void JitLogger::LogRecordedBuffer(const wasm::WasmCode* code, const char* name,
695696
event.code_len = code->instructions().length();
696697
event.name.str = name;
697698
event.name.len = length;
699+
event.isolate = reinterpret_cast<v8::Isolate*>(isolate_);
698700
code_event_handler_(&event);
699701
}
700702

@@ -713,6 +715,7 @@ void JitLogger::CodeMoveEvent(AbstractCode* from, Address to) {
713715

714716
// Calculate the new start address of the instructions.
715717
event.new_code_start = reinterpret_cast<void*>(to + header_size);
718+
event.isolate = reinterpret_cast<v8::Isolate*>(isolate_);
716719

717720
code_event_handler_(&event);
718721
}
@@ -729,6 +732,7 @@ void JitLogger::AddCodeLinePosInfoEvent(
729732
event.line_info.offset = pc_offset;
730733
event.line_info.pos = position;
731734
event.line_info.position_type = position_type;
735+
event.isolate = reinterpret_cast<v8::Isolate*>(isolate_);
732736

733737
code_event_handler_(&event);
734738
}
@@ -738,6 +742,7 @@ void* JitLogger::StartCodePosInfoEvent() {
738742
JitCodeEvent event;
739743
memset(&event, 0, sizeof(event));
740744
event.type = JitCodeEvent::CODE_START_LINE_INFO_RECORDING;
745+
event.isolate = reinterpret_cast<v8::Isolate*>(isolate_);
741746

742747
code_event_handler_(&event);
743748
return event.user_data;
@@ -750,6 +755,7 @@ void JitLogger::EndCodePosInfoEvent(Address start_address,
750755
event.type = JitCodeEvent::CODE_END_LINE_INFO_RECORDING;
751756
event.code_start = reinterpret_cast<void*>(start_address);
752757
event.user_data = jit_handler_data;
758+
event.isolate = reinterpret_cast<v8::Isolate*>(isolate_);
753759

754760
code_event_handler_(&event);
755761
}
@@ -1967,17 +1973,17 @@ bool Logger::SetUp(Isolate* isolate) {
19671973
log_ = new Log(this, log_file_name.str().c_str());
19681974

19691975
if (FLAG_perf_basic_prof) {
1970-
perf_basic_logger_ = new PerfBasicLogger();
1976+
perf_basic_logger_ = new PerfBasicLogger(isolate);
19711977
AddCodeEventListener(perf_basic_logger_);
19721978
}
19731979

19741980
if (FLAG_perf_prof) {
1975-
perf_jit_logger_ = new PerfJitLogger();
1981+
perf_jit_logger_ = new PerfJitLogger(isolate);
19761982
AddCodeEventListener(perf_jit_logger_);
19771983
}
19781984

19791985
if (FLAG_ll_prof) {
1980-
ll_logger_ = new LowLevelLogger(log_file_name.str().c_str());
1986+
ll_logger_ = new LowLevelLogger(isolate, log_file_name.str().c_str());
19811987
AddCodeEventListener(ll_logger_);
19821988
}
19831989

@@ -2012,7 +2018,7 @@ void Logger::SetCodeEventHandler(uint32_t options,
20122018
}
20132019

20142020
if (event_handler) {
2015-
jit_logger_ = new JitLogger(event_handler);
2021+
jit_logger_ = new JitLogger(isolate_, event_handler);
20162022
AddCodeEventListener(jit_logger_);
20172023
if (options & kJitCodeEventEnumExisting) {
20182024
HandleScope scope(isolate_);

src/log.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class TimerEventScope {
414414

415415
class CodeEventLogger : public CodeEventListener {
416416
public:
417-
CodeEventLogger();
417+
explicit CodeEventLogger(Isolate* isolate);
418418
~CodeEventLogger() override;
419419

420420
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode* code,
@@ -438,6 +438,9 @@ class CodeEventLogger : public CodeEventListener {
438438
void CodeDeoptEvent(Code* code, DeoptimizeKind kind, Address pc,
439439
int fp_to_sp_delta) override {}
440440

441+
protected:
442+
Isolate* isolate_;
443+
441444
private:
442445
class NameBuffer;
443446

@@ -450,6 +453,7 @@ class CodeEventLogger : public CodeEventListener {
450453
};
451454

452455
struct CodeEvent {
456+
Isolate* isolate_;
453457
uintptr_t code_start_address;
454458
size_t code_size;
455459
Handle<String> function_name;

src/perf-jit.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void PerfJitLogger::CloseMarkerFile(void* marker_address) {
164164
munmap(marker_address, page_size);
165165
}
166166

167-
PerfJitLogger::PerfJitLogger() {
167+
PerfJitLogger::PerfJitLogger(Isolate* isolate) : CodeEventLogger(isolate) {
168168
base::LockGuard<base::RecursiveMutex> guard_file(file_mutex_.Pointer());
169169

170170
reference_count_++;

src/perf-jit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace internal {
3838
// Linux perf tool logging support
3939
class PerfJitLogger : public CodeEventLogger {
4040
public:
41-
PerfJitLogger();
41+
explicit PerfJitLogger(Isolate* isolate);
4242
virtual ~PerfJitLogger();
4343

4444
void CodeMoveEvent(AbstractCode* from, Address to) override;
@@ -118,6 +118,8 @@ class PerfJitLogger : public CodeEventLogger {
118118
// PerfJitLogger is only implemented on Linux
119119
class PerfJitLogger : public CodeEventLogger {
120120
public:
121+
explicit PerfJitLogger(Isolate* isolate) : CodeEventLogger(isolate) {}
122+
121123
void CodeMoveEvent(AbstractCode* from, Address to) override {
122124
UNIMPLEMENTED();
123125
}

src/snapshot/serializer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace internal {
2020

2121
class CodeAddressMap : public CodeEventLogger {
2222
public:
23-
explicit CodeAddressMap(Isolate* isolate) : isolate_(isolate) {
23+
explicit CodeAddressMap(Isolate* isolate) : CodeEventLogger(isolate) {
2424
isolate->logger()->AddCodeEventListener(this);
2525
}
2626

@@ -125,7 +125,6 @@ class CodeAddressMap : public CodeEventLogger {
125125
}
126126

127127
NameMap address_to_name_map_;
128-
Isolate* isolate_;
129128
};
130129

131130
template <class AllocatorT = DefaultSerializerAllocator>

src/third_party/vtune/vtune-jit.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ void VTUNEJITInterface::event_handler(const v8::JitCodeEvent* event) {
182182
if ((*script->GetScriptName())->IsString()) {
183183
Local<String> script_name =
184184
Local<String>::Cast(script->GetScriptName());
185-
temp_file_name = new char[script_name->Utf8Length() + 1];
185+
temp_file_name =
186+
new char[script_name->Utf8Length(event->isolate) + 1];
186187
script_name->WriteUtf8(temp_file_name);
187188
jmethod.source_file_name = temp_file_name;
188189
}

0 commit comments

Comments
 (0)