Back out "Check for thread consistency in JSCRuntime"

Summary:
This check is too aggressive.  We will consider putting it back once we are
more certain nothing will trigger it.

Differential Revision: D13350907

fbshipit-source-id: 6033bdbfe7adb2a18bdf889c090cf271497605e5
This commit is contained in:
Marc Horowitz 2018-12-05 16:57:22 -08:00 committed by Facebook Github Bot
parent 01d7aad548
commit 3f0f25f73c
2 changed files with 9 additions and 33 deletions

View File

@ -53,8 +53,6 @@ void Instance::initializeBridge(
m_syncCV.notify_all(); m_syncCV.notify_all();
}); });
// If the NativeToJsBridge ctor throws an exception, this check will
// likely happen before before the redbox can be rendered.
CHECK(nativeToJsBridge_); CHECK(nativeToJsBridge_);
} }

View File

@ -28,14 +28,6 @@ struct Lock {
void unlock(const jsc::JSCRuntime&) const {} void unlock(const jsc::JSCRuntime&) const {}
}; };
#if __has_builtin(__builtin_expect)
#define JSC_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
#define JSC_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
#else
#define JSC_LIKELY(EXPR) (EXPR)
#define JSC_UNLIKELY(EXPR) (EXPR)
#endif
class JSCRuntime : public jsi::Runtime { class JSCRuntime : public jsi::Runtime {
public: public:
// Creates new context in new context group // Creates new context in new context group
@ -199,32 +191,23 @@ class JSCRuntime : public jsi::Runtime {
void checkException(JSValueRef exc, const char* msg); void checkException(JSValueRef exc, const char* msg);
void checkException(JSValueRef res, JSValueRef exc, const char* msg); void checkException(JSValueRef res, JSValueRef exc, const char* msg);
void checkThreadId() {
#ifndef NDEBUG
if (JSC_UNLIKELY(tid_ != std::this_thread::get_id())) {
// In the version of JSC on iOS 11, creating a JSContext on one
// thread and using it on another can trigger subtle and nearly
// impossible to debug reentrancy-related crashes in the VM (see
// https://bugs.webkit.org/show_bug.cgi?id=186827). In !NDEBUG
// builds, check for this case and throw an exception, so it can
// be detected early. This could be called anywhere, but for
// now, it's called only in a few less frequently used places to
// avoid unnecessary checks.
throw std::logic_error("Detected JSC thread hazard");
}
#endif
}
JSGlobalContextRef ctx_; JSGlobalContextRef ctx_;
std::atomic<bool> ctxInvalid_; std::atomic<bool> ctxInvalid_;
std::string desc_; std::string desc_;
#ifndef NDEBUG #ifndef NDEBUG
mutable std::atomic<intptr_t> objectCounter_; mutable std::atomic<intptr_t> objectCounter_;
mutable std::atomic<intptr_t> stringCounter_; mutable std::atomic<intptr_t> stringCounter_;
std::thread::id tid_;
#endif #endif
}; };
#if __has_builtin(__builtin_expect)
#define JSC_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
#define JSC_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)
#else
#define JSC_LIKELY(EXPR) (EXPR)
#define JSC_UNLIKELY(EXPR) (EXPR)
#endif
#define JSC_ASSERT(x) \ #define JSC_ASSERT(x) \
do { \ do { \
if (JSC_UNLIKELY(!!(x))) { \ if (JSC_UNLIKELY(!!(x))) { \
@ -309,8 +292,7 @@ JSCRuntime::JSCRuntime(JSGlobalContextRef ctx)
#ifndef NDEBUG #ifndef NDEBUG
, ,
objectCounter_(0), objectCounter_(0),
stringCounter_(0), stringCounter_(0)
tid_(std::this_thread::get_id())
#endif #endif
{ {
} }
@ -335,8 +317,6 @@ JSCRuntime::~JSCRuntime() {
void JSCRuntime::evaluateJavaScript( void JSCRuntime::evaluateJavaScript(
std::unique_ptr<const jsi::Buffer> buffer, std::unique_ptr<const jsi::Buffer> buffer,
const std::string& sourceURL) { const std::string& sourceURL) {
checkThreadId();
std::string tmp( std::string tmp(
reinterpret_cast<const char*>(buffer->data()), buffer->size()); reinterpret_cast<const char*>(buffer->data()), buffer->size());
JSStringRef sourceRef = JSStringCreateWithUTF8CString(tmp.c_str()); JSStringRef sourceRef = JSStringCreateWithUTF8CString(tmp.c_str());
@ -355,8 +335,6 @@ void JSCRuntime::evaluateJavaScript(
} }
jsi::Object JSCRuntime::global() { jsi::Object JSCRuntime::global() {
checkThreadId();
return createObject(JSContextGetGlobalObject(ctx_)); return createObject(JSContextGetGlobalObject(ctx_));
} }