[+] Safepoint parking apis

[+] Noted extension APIs
(private)
[+] IsolateSafepoint::NotifyParkEx
[+] IsolateSafepoint::NotifyUnpark
[*] Continued hacky bug fix as """described""" below

-------------------------------------------------------------------------------------------------
Last aurora commit: 7c599206 continued

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#	src/heap/safepoint.cc
-----------
[-] (USE AFTER FREE) quick hack: removing a mutex guard on shared RemoveClient to temporarily mitigate a crash on deinit
-----------
well, this is fucking dumb. i think someone at google also figured out this can lead to crashing. their solution: remove the mutex with a call to AssertActive.
considering my issue was related to a dead context with everything else alive, i dont want to find out what that AssertActive is doing. reverting v8 change.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

3172b30fe4 - Dominik Inführ, and Michael Lippautz

Fuck safety for now. The entire file will be different in 3 months time, anyway. I just want my software to actually fucking work.
This commit is contained in:
Reece Wilson 2023-02-06 20:54:16 +00:00
parent 7c5992067e
commit 465f778309
3 changed files with 61 additions and 14 deletions

View File

@ -1127,20 +1127,41 @@ bool Data::IsFunctionTemplate() const {
bool Data::IsContext() const { return Utils::OpenHandle(this)->IsContext(); }
size_t GetCPUFeatureMask() {
// Reece:
V8_EXPORT size_t GetCPUFeatureMask() {
return internal::CpuFeatures::SupportedFeatures();
}
size_t GetCPUFeatureMaskRescan() {
// Reece:
V8_EXPORT size_t GetCPUFeatureMaskRescan() {
internal::CpuFeatures::initialized_ = 0;
internal::CpuFeatures::supported_ = 0;
return internal::CpuFeatures::SupportedFeatures();
}
void SetCPUFeatureMask(size_t features) {
// Reece:
V8_EXPORT void SetCPUFeatureMask(size_t features) {
internal::CpuFeatures::supported_ = features;
}
// Reece:
V8_EXPORT void Safepoint(v8::Isolate* pIsolate) {
reinterpret_cast<i::Isolate*>(pIsolate)
->heap()
->main_thread_local_heap()
->Safepoint();
}
// Reece:
V8_EXPORT void SafepointParkIsolate(v8::Isolate* pIsolate) {
reinterpret_cast<i::Isolate*>(pIsolate)->heap()->safepoint()->NotifyParkEx();
}
// Reece:
V8_EXPORT void SafepointUnparkIsolate(v8::Isolate* pIsolate) {
reinterpret_cast<i::Isolate*>(pIsolate)->heap()->safepoint()->NotifyUnpark();
}
void Context::Enter() {
i::DisallowGarbageCollection no_gc;
i::Context env = *Utils::OpenHandle(this);
@ -2703,6 +2724,7 @@ MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundScript(
return CompileUnboundInternal(v8_isolate, source, options, no_cache_reason);
}
// Reece:
MaybeLocal<v8::Value> ScriptCompiler::EvaluateGlobal(
v8::Isolate* isolate, v8::Local<v8::String> source,
bool repl) {
@ -5445,6 +5467,7 @@ MaybeLocal<Object> Function::NewInstanceWithSideEffectType(
RETURN_ESCAPED(result);
}
// Reece:
MaybeLocal<Function> Function::Bind(v8::Local<v8::Object> that,
v8::Local<v8::Array> bound_args) {
i::Handle<i::JSReceiver> self;
@ -6053,6 +6076,7 @@ bool v8::String::IsExternalOneByte() const {
return false;
}
// Reece:
v8::Local<v8::String> v8::String::GloballyInternalize() {
i::DisallowGarbageCollection no_gc;
i::Handle<i::String> str = Utils::OpenHandle(this);

View File

@ -206,6 +206,10 @@ void IsolateSafepoint::WaitInUnpark() { barrier_.WaitInUnpark(); }
void IsolateSafepoint::NotifyPark() { barrier_.NotifyPark(); }
void IsolateSafepoint::NotifyParkEx() { barrier_.NotifyParkEx(); }
void IsolateSafepoint::NotifyUnpark() { barrier_.NotifyUnpark(); }
void IsolateSafepoint::WaitUntilRunningThreadsInSafepoint(
const PerClientSafepointData* client_data) {
barrier_.WaitUntilRunningThreadsInSafepoint(client_data->running());
@ -243,6 +247,19 @@ void IsolateSafepoint::Barrier::NotifyPark() {
cv_stopped_.NotifyOne();
}
void IsolateSafepoint::Barrier::NotifyParkEx() {
base::MutexGuard guard(&mutex_);
armed_ = true;
stopped_++;
cv_stopped_.NotifyOne();
}
void IsolateSafepoint::Barrier::NotifyUnpark() {
base::MutexGuard guard(&mutex_);
stopped_--;
cv_stopped_.NotifyOne();
}
void IsolateSafepoint::Barrier::WaitInSafepoint() {
base::MutexGuard guard(&mutex_);
CHECK(IsArmed());

View File

@ -43,6 +43,18 @@ class IsolateSafepoint final {
V8_EXPORT_PRIVATE void AssertMainThreadIsOnlyThread();
// Wait until unpark operation is safe again.
void WaitInUnpark();
// Enter the safepoint from a running thread.
void WaitInSafepoint();
// Running thread reached a safepoint by parking itself.
void NotifyPark();
void NotifyParkEx();
void NotifyUnpark();
private:
class Barrier {
base::Mutex mutex_;
@ -57,26 +69,20 @@ class IsolateSafepoint final {
public:
Barrier() : armed_(false), stopped_(0) {}
void Arm();
void Disarm();
void WaitUntilRunningThreadsInSafepoint(size_t running);
void Arm();
void Disarm();
void WaitInSafepoint();
void WaitInUnpark();
void NotifyUnpark();
void NotifyParkEx();
void NotifyPark();
};
enum class IncludeMainThread { kYes, kNo };
// Wait until unpark operation is safe again.
void WaitInUnpark();
// Enter the safepoint from a running thread.
void WaitInSafepoint();
// Running thread reached a safepoint by parking itself.
void NotifyPark();
// Methods for entering/leaving local safepoint scopes.
void EnterLocalSafepointScope();
void LeaveLocalSafepointScope();