Michaël ZassoandAnna Henningsen authored and Michaël Zasso committed 2019-09-19 08:48:17 +02:00
1 parent 4eeb2a99e5
commit e95f866956
12 files changed
+657 -222

No files matched your search

+2
View File
@@ -174,6 +174,8 @@ class Internals {
static const int kNodeStateMask = 0x7;
static const int kNodeStateIsWeakValue = 2;
static const int kNodeStateIsPendingValue = 3;
static const int kNodeIsIndependentShift = 3;
static const int kNodeIsActiveShift = 4;
static const int kFirstNonstringType = 0x40;
static const int kOddballType = 0x43;
+6 -3
View File
@@ -356,8 +356,9 @@ class V8_EXPORT CpuProfiler {
* initialized. The profiler object must be disposed after use by calling
* |Dispose| method.
*/
static CpuProfiler* New(Isolate* isolate);
static CpuProfiler* New(Isolate* isolate,
CpuProfilingNamingMode = kDebugNaming);
CpuProfilingNamingMode mode);
/**
* Synchronously collect current stack sample in all profilers attached to
@@ -406,8 +407,10 @@ class V8_EXPORT CpuProfiler {
* discarded.
*/
void StartProfiling(
Local<String> title, CpuProfilingMode mode, bool record_samples = false,
unsigned max_samples = CpuProfilingOptions::kNoSampleLimit);
Local<String> title, CpuProfilingMode mode, bool record_samples = false);
void StartProfiling(
Local<String> title, CpuProfilingMode mode, bool record_samples,
unsigned max_samples);
/**
* The same as StartProfiling above, but the CpuProfilingMode defaults to
* kLeafNodeLineNumbers mode, which was the previous default behavior of the
+18
View File
@@ -194,6 +194,14 @@ class PersistentValueMapBase {
return SetReturnValueFromVal(&returnValue, Traits::Get(&impl_, key));
}
/**
* Call V8::RegisterExternallyReferencedObject with the map value for given
* key.
*/
V8_DEPRECATED(
"Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference",
inline void RegisterExternallyReferencedObject(K& key));
/**
* Return value for key and remove it from the map.
*/
@@ -344,6 +352,16 @@ class PersistentValueMapBase {
const char* label_;
};
template <typename K, typename V, typename Traits>
inline void
PersistentValueMapBase<K, V, Traits>::RegisterExternallyReferencedObject(
K& key) {
assert(Contains(key));
V8::RegisterExternallyReferencedObject(
reinterpret_cast<internal::Address*>(FromVal(Traits::Get(&impl_, key))),
reinterpret_cast<internal::Isolate*>(GetIsolate()));
}
template <typename K, typename V, typename Traits>
class PersistentValueMap : public PersistentValueMapBase<K, V, Traits> {
public:
+177 -9
View File
@@ -122,6 +122,7 @@ class ExternalString;
class Isolate;
class LocalEmbedderHeapTracer;
class MicrotaskQueue;
class NeverReadOnlySpaceObject;
struct ScriptStreamingData;
template<typename T> class CustomArguments;
class PropertyCallbackArguments;
@@ -544,6 +545,38 @@ template <class T> class PersistentBase {
*/
V8_INLINE void AnnotateStrongRetainer(const char* label);
/**
* Allows the embedder to tell the v8 garbage collector that a certain object
* is alive. Only allowed when the embedder is asked to trace its heap by
* EmbedderHeapTracer.
*/
V8_DEPRECATED(
"Used TracedGlobal and EmbedderHeapTracer::RegisterEmbedderReference",
V8_INLINE void RegisterExternalReference(Isolate* isolate) const);
/**
* Marks the reference to this object independent. Garbage collector is free
* to ignore any object groups containing this object. Weak callback for an
* independent handle should not assume that it will be preceded by a global
* GC prologue callback or followed by a global GC epilogue callback.
*/
V8_DEPRECATED(
"Weak objects are always considered independent. "
"Use TracedGlobal when trying to use EmbedderHeapTracer. "
"Use a strong handle when trying to keep an object alive.",
V8_INLINE void MarkIndependent());
/**
* Marks the reference to this object as active. The scavenge garbage
* collection should not reclaim the objects marked as active, even if the
* object held by the handle is otherwise unreachable.
*
* This bit is cleared after the each garbage collection pass.
*/
V8_DEPRECATED("Use TracedGlobal.", V8_INLINE void MarkActive());
V8_DEPRECATED("See MarkIndependent.", V8_INLINE bool IsIndependent() const);
/** Returns true if the handle's reference is weak. */
V8_INLINE bool IsWeak() const;
@@ -2525,6 +2558,9 @@ class V8_EXPORT Value : public Data {
V8_WARN_UNUSED_RESULT MaybeLocal<BigInt> ToBigInt(
Local<Context> context) const;
V8_DEPRECATED("ToBoolean can never throw. Use Local version.",
V8_WARN_UNUSED_RESULT MaybeLocal<Boolean> ToBoolean(
Local<Context> context) const);
V8_WARN_UNUSED_RESULT MaybeLocal<Number> ToNumber(
Local<Context> context) const;
V8_WARN_UNUSED_RESULT MaybeLocal<String> ToString(
@@ -2540,6 +2576,16 @@ class V8_EXPORT Value : public Data {
V8_WARN_UNUSED_RESULT MaybeLocal<Int32> ToInt32(Local<Context> context) const;
Local<Boolean> ToBoolean(Isolate* isolate) const;
V8_DEPRECATED("Use maybe version",
Local<Number> ToNumber(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<String> ToString(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Object> ToObject(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Integer> ToInteger(Isolate* isolate) const);
V8_DEPRECATED("Use maybe version",
Local<Int32> ToInt32(Isolate* isolate) const);
/**
* Attempts to convert a string to an array index.
@@ -2550,6 +2596,9 @@ class V8_EXPORT Value : public Data {
bool BooleanValue(Isolate* isolate) const;
V8_DEPRECATED("BooleanValue can never throw. Use Isolate version.",
V8_WARN_UNUSED_RESULT Maybe<bool> BooleanValue(
Local<Context> context) const);
V8_WARN_UNUSED_RESULT Maybe<double> NumberValue(Local<Context> context) const;
V8_WARN_UNUSED_RESULT Maybe<int64_t> IntegerValue(
Local<Context> context) const;
@@ -2869,23 +2918,43 @@ class V8_EXPORT String : public Name {
V8_INLINE static String* Cast(v8::Value* obj);
// TODO(dcarney): remove with deprecation of New functions.
enum NewStringType {
kNormalString = static_cast<int>(v8::NewStringType::kNormal),
kInternalizedString = static_cast<int>(v8::NewStringType::kInternalized)
};
/** Allocates a new string from UTF-8 data.*/
static V8_DEPRECATED(
"Use maybe version",
Local<String> NewFromUtf8(Isolate* isolate, const char* data,
NewStringType type = kNormalString,
int length = -1));
/** Allocates a new string from UTF-8 data. Only returns an empty value when
* length > kMaxLength. **/
static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromUtf8(
Isolate* isolate, const char* data,
NewStringType type = NewStringType::kNormal, int length = -1);
Isolate* isolate, const char* data, v8::NewStringType type,
int length = -1);
/** Allocates a new string from Latin-1 data. Only returns an empty value
* when length > kMaxLength. **/
static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromOneByte(
Isolate* isolate, const uint8_t* data,
NewStringType type = NewStringType::kNormal, int length = -1);
Isolate* isolate, const uint8_t* data, v8::NewStringType type,
int length = -1);
/** Allocates a new string from UTF-16 data.*/
static V8_DEPRECATED(
"Use maybe version",
Local<String> NewFromTwoByte(Isolate* isolate, const uint16_t* data,
NewStringType type = kNormalString,
int length = -1));
/** Allocates a new string from UTF-16 data. Only returns an empty value when
* length > kMaxLength. **/
static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewFromTwoByte(
Isolate* isolate, const uint16_t* data,
NewStringType type = NewStringType::kNormal, int length = -1);
Isolate* isolate, const uint16_t* data, v8::NewStringType type,
int length = -1);
/**
* Creates a new string by concatenating the left and the right strings
@@ -2924,6 +2993,10 @@ class V8_EXPORT String : public Name {
* should the underlying buffer be deallocated or modified except through the
* destructor of the external string resource.
*/
static V8_DEPRECATED(
"Use maybe version",
Local<String> NewExternal(Isolate* isolate,
ExternalOneByteStringResource* resource));
static V8_WARN_UNUSED_RESULT MaybeLocal<String> NewExternalOneByte(
Isolate* isolate, ExternalOneByteStringResource* resource);
@@ -3857,6 +3930,9 @@ class ReturnValue {
}
// Local setters
template <typename S>
V8_INLINE V8_DEPRECATED("Use Global<> instead",
void Set(const Persistent<S>& handle));
template <typename S>
V8_INLINE void Set(const Global<S>& handle);
template <typename S>
V8_INLINE void Set(const TracedGlobal<S>& handle);
@@ -5247,6 +5323,38 @@ class V8_EXPORT Date : public Object {
V8_INLINE static Date* Cast(Value* obj);
/**
* Time zone redetection indicator for
* DateTimeConfigurationChangeNotification.
*
* kSkip indicates V8 that the notification should not trigger redetecting
* host time zone. kRedetect indicates V8 that host time zone should be
* redetected, and used to set the default time zone.
*
* The host time zone detection may require file system access or similar
* operations unlikely to be available inside a sandbox. If v8 is run inside a
* sandbox, the host time zone has to be detected outside the sandbox before
* calling DateTimeConfigurationChangeNotification function.
*/
enum class TimeZoneDetection { kSkip, kRedetect };
/**
* Notification that the embedder has changed the time zone,
* daylight savings time, or other date / time configuration
* parameters. V8 keeps a cache of various values used for
* date / time computation. This notification will reset
* those cached values for the current context so that date /
* time configuration changes would be reflected in the Date
* object.
*
* This API should not be called more than needed as it will
* negatively impact the performance of date operations.
*/
V8_DEPRECATED("Use Isolate::DateTimeConfigurationChangeNotification",
static void DateTimeConfigurationChangeNotification(
Isolate* isolate, TimeZoneDetection time_zone_detection =
TimeZoneDetection::kSkip));
private:
static void CheckCast(Value* obj);
};
@@ -5934,6 +6042,21 @@ class V8_EXPORT FunctionTemplate : public Template {
*/
void SetAcceptAnyReceiver(bool value);
/**
* Determines whether the __proto__ accessor ignores instances of
* the function template. If instances of the function template are
* ignored, __proto__ skips all instances and instead returns the
* next object in the prototype chain.
*
* Call with a value of true to make the __proto__ accessor ignore
* instances of the function template. Call with a value of false
* to make the __proto__ accessor not ignore instances of the
* function template. By default, instances of a function template
* are not ignored.
*/
V8_DEPRECATED("This feature is incompatible with ES6+.",
void SetHiddenPrototype(bool value));
/**
* Sets the ReadOnly flag in the attributes of the 'prototype' property
* of functions created from this FunctionTemplate to true.
@@ -8690,9 +8813,7 @@ class V8_EXPORT V8 {
* Sets V8 flags from a string.
*/
static void SetFlagsFromString(const char* str);
static void SetFlagsFromString(const char* str, size_t length);
V8_DEPRECATED("use size_t version",
static void SetFlagsFromString(const char* str, int length));
static void SetFlagsFromString(const char* str, int length);
/**
* Sets V8 flags from the command line.
@@ -8863,6 +8984,9 @@ class V8_EXPORT V8 {
const char* label);
static Value* Eternalize(Isolate* isolate, Value* handle);
static void RegisterExternallyReferencedObject(internal::Address* location,
internal::Isolate* isolate);
template <class K, class V, class T>
friend class PersistentValueMapBase;
@@ -9818,6 +9942,14 @@ void Persistent<T, M>::Copy(const Persistent<S, M2>& that) {
M::Copy(that, this);
}
template <class T>
bool PersistentBase<T>::IsIndependent() const {
typedef internal::Internals I;
if (this->IsEmpty()) return false;
return I::GetNodeFlag(reinterpret_cast<internal::Address*>(this->val_),
I::kNodeIsIndependentShift);
}
template <class T>
bool PersistentBase<T>::IsWeak() const {
typedef internal::Internals I;
@@ -9884,6 +10016,31 @@ void PersistentBase<T>::AnnotateStrongRetainer(const char* label) {
label);
}
template <class T>
void PersistentBase<T>::RegisterExternalReference(Isolate* isolate) const {
if (IsEmpty()) return;
V8::RegisterExternallyReferencedObject(
reinterpret_cast<internal::Address*>(this->val_),
reinterpret_cast<internal::Isolate*>(isolate));
}
template <class T>
void PersistentBase<T>::MarkIndependent() {
typedef internal::Internals I;
if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
I::kNodeIsIndependentShift);
}
template <class T>
void PersistentBase<T>::MarkActive() {
typedef internal::Internals I;
if (this->IsEmpty()) return;
I::UpdateNodeFlag(reinterpret_cast<internal::Address*>(this->val_), true,
I::kNodeIsActiveShift);
}
template <class T>
void PersistentBase<T>::SetWrapperClassId(uint16_t class_id) {
typedef internal::Internals I;
@@ -10009,6 +10166,17 @@ void TracedGlobal<T>::SetFinalizationCallback(
template <typename T>
ReturnValue<T>::ReturnValue(internal::Address* slot) : value_(slot) {}
template<typename T>
template<typename S>
void ReturnValue<T>::Set(const Persistent<S>& handle) {
TYPE_CHECK(T, S);
if (V8_UNLIKELY(handle.IsEmpty())) {
*value_ = GetDefaultValue();
} else {
*value_ = *reinterpret_cast<internal::Address*>(*handle);
}
}
template <typename T>
template <typename S>
void ReturnValue<T>::Set(const Global<S>& handle) {
+115 -20
View File
@@ -883,17 +883,13 @@ void V8::SetDcheckErrorHandler(DcheckErrorCallback that) {
}
void V8::SetFlagsFromString(const char* str) {
SetFlagsFromString(str, strlen(str));
}
void V8::SetFlagsFromString(const char* str, size_t length) {
i::FlagList::SetFlagsFromString(str, length);
i::FlagList::EnforceFlagImplications();
SetFlagsFromString(str, static_cast<int>(strlen(str)));
}
void V8::SetFlagsFromString(const char* str, int length) {
CHECK_LE(0, length);
SetFlagsFromString(str, static_cast<size_t>(length));
i::FlagList::SetFlagsFromString(str, static_cast<size_t>(length));
i::FlagList::EnforceFlagImplications();
}
void V8::SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags) {
@@ -1048,6 +1044,11 @@ void V8::MoveTracedGlobalReference(internal::Address** from,
i::GlobalHandles::MoveTracedGlobal(from, to);
}
void V8::RegisterExternallyReferencedObject(i::Address* location,
i::Isolate* isolate) {
isolate->heap()->RegisterExternallyReferencedObject(location);
}
void V8::MakeWeak(i::Address* location, void* parameter,
WeakCallbackInfo<void>::Callback weak_callback,
WeakCallbackType type) {
@@ -1619,6 +1620,10 @@ void FunctionTemplate::SetAcceptAnyReceiver(bool value) {
info->set_accept_any_receiver(value);
}
void FunctionTemplate::SetHiddenPrototype(bool value) {
/* No-op for ABI compatibility. */
}
void FunctionTemplate::ReadOnlyPrototype() {
auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::ReadOnlyPrototype");
@@ -3488,6 +3493,12 @@ MaybeLocal<String> Value::ToString(Local<Context> context) const {
RETURN_ESCAPED(result);
}
Local<String> Value::ToString(Isolate* isolate) const {
RETURN_TO_LOCAL_UNCHECKED(ToString(isolate->GetCurrentContext()), String);
}
MaybeLocal<String> Value::ToDetailString(Local<Context> context) const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (obj->IsString()) return ToApiHandle<String>(obj);
@@ -3509,6 +3520,11 @@ MaybeLocal<Object> Value::ToObject(Local<Context> context) const {
RETURN_ESCAPED(result);
}
Local<v8::Object> Value::ToObject(Isolate* isolate) const {
RETURN_TO_LOCAL_UNCHECKED(ToObject(isolate->GetCurrentContext()), Object);
}
MaybeLocal<BigInt> Value::ToBigInt(Local<Context> context) const {
i::Handle<i::Object> obj = Utils::OpenHandle(this);
if (obj->IsBigInt()) return ToApiHandle<BigInt>(obj);
@@ -3525,6 +3541,11 @@ bool Value::BooleanValue(Isolate* v8_isolate) const {
reinterpret_cast<i::Isolate*>(v8_isolate));
}
MaybeLocal<Boolean> Value::ToBoolean(Local<Context> context) const {
return ToBoolean(context->GetIsolate());
}
Local<Boolean> Value::ToBoolean(Isolate* v8_isolate) const {
auto isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
return ToApiHandle<Boolean>(
@@ -3542,6 +3563,12 @@ MaybeLocal<Number> Value::ToNumber(Local<Context> context) const {
RETURN_ESCAPED(result);
}
Local<Number> Value::ToNumber(Isolate* isolate) const {
RETURN_TO_LOCAL_UNCHECKED(ToNumber(isolate->GetCurrentContext()), Number);
}
MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsSmi()) return ToApiHandle<Integer>(obj);
@@ -3553,6 +3580,12 @@ MaybeLocal<Integer> Value::ToInteger(Local<Context> context) const {
RETURN_ESCAPED(result);
}
Local<Integer> Value::ToInteger(Isolate* isolate) const {
RETURN_TO_LOCAL_UNCHECKED(ToInteger(isolate->GetCurrentContext()), Integer);
}
MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsSmi()) return ToApiHandle<Int32>(obj);
@@ -3564,6 +3597,12 @@ MaybeLocal<Int32> Value::ToInt32(Local<Context> context) const {
RETURN_ESCAPED(result);
}
Local<Int32> Value::ToInt32(Isolate* isolate) const {
RETURN_TO_LOCAL_UNCHECKED(ToInt32(isolate->GetCurrentContext()), Int32);
}
MaybeLocal<Uint32> Value::ToUint32(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsSmi()) return ToApiHandle<Uint32>(obj);
@@ -3790,6 +3829,13 @@ void v8::RegExp::CheckCast(v8::Value* that) {
"Could not convert to regular expression");
}
Maybe<bool> Value::BooleanValue(Local<Context> context) const {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(context->GetIsolate());
return Just(Utils::OpenHandle(this)->BooleanValue(isolate));
}
Maybe<double> Value::NumberValue(Local<Context> context) const {
auto obj = Utils::OpenHandle(this);
if (obj->IsNumber()) return Just(obj->Number());
@@ -6115,9 +6161,9 @@ inline int StringLength(const uint16_t* string) {
V8_WARN_UNUSED_RESULT
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
NewStringType type,
v8::NewStringType type,
i::Vector<const char> string) {
if (type == NewStringType::kInternalized) {
if (type == v8::NewStringType::kInternalized) {
return factory->InternalizeUtf8String(string);
}
return factory->NewStringFromUtf8(string);
@@ -6125,9 +6171,9 @@ inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
V8_WARN_UNUSED_RESULT
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
NewStringType type,
v8::NewStringType type,
i::Vector<const uint8_t> string) {
if (type == NewStringType::kInternalized) {
if (type == v8::NewStringType::kInternalized) {
return factory->InternalizeString(string);
}
return factory->NewStringFromOneByte(string);
@@ -6135,14 +6181,15 @@ inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
V8_WARN_UNUSED_RESULT
inline i::MaybeHandle<i::String> NewString(i::Factory* factory,
NewStringType type,
v8::NewStringType type,
i::Vector<const uint16_t> string) {
if (type == NewStringType::kInternalized) {
if (type == v8::NewStringType::kInternalized) {
return factory->InternalizeString(string);
}
return factory->NewStringFromTwoByte(string);
}
STATIC_ASSERT(v8::String::kMaxLength == i::String::kMaxLength);
} // anonymous namespace
@@ -6167,21 +6214,43 @@ STATIC_ASSERT(v8::String::kMaxLength == i::String::kMaxLength);
result = Utils::ToLocal(handle_result); \
}
Local<String> String::NewFromUtf8(Isolate* isolate,
const char* data,
NewStringType type,
int length) {
NEW_STRING(isolate, String, NewFromUtf8, char, data,
static_cast<v8::NewStringType>(type), length);
RETURN_TO_LOCAL_UNCHECKED(result, String);
}
MaybeLocal<String> String::NewFromUtf8(Isolate* isolate, const char* data,
NewStringType type, int length) {
v8::NewStringType type, int length) {
NEW_STRING(isolate, String, NewFromUtf8, char, data, type, length);
return result;
}
MaybeLocal<String> String::NewFromOneByte(Isolate* isolate, const uint8_t* data,
NewStringType type, int length) {
v8::NewStringType type, int length) {
NEW_STRING(isolate, String, NewFromOneByte, uint8_t, data, type, length);
return result;
}
Local<String> String::NewFromTwoByte(Isolate* isolate,
const uint16_t* data,
NewStringType type,
int length) {
NEW_STRING(isolate, String, NewFromTwoByte, uint16_t, data,
static_cast<v8::NewStringType>(type), length);
RETURN_TO_LOCAL_UNCHECKED(result, String);
}
MaybeLocal<String> String::NewFromTwoByte(Isolate* isolate,
const uint16_t* data,
NewStringType type, int length) {
v8::NewStringType type, int length) {
NEW_STRING(isolate, String, NewFromTwoByte, uint16_t, data, type, length);
return result;
}
@@ -6248,6 +6317,13 @@ MaybeLocal<String> v8::String::NewExternalOneByte(
}
}
Local<String> v8::String::NewExternal(
Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String);
}
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
i::DisallowHeapAllocation no_allocation;
@@ -6521,14 +6597,23 @@ double v8::Date::ValueOf() const {
// Assert that the static TimeZoneDetection cast in
// DateTimeConfigurationChangeNotification is valid.
#define TIME_ZONE_DETECTION_ASSERT_EQ(value) \
STATIC_ASSERT( \
static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
static_cast<int>(base::TimezoneCache::TimeZoneDetection::value));
#define TIME_ZONE_DETECTION_ASSERT_EQ(value) \
STATIC_ASSERT( \
static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
static_cast<int>(base::TimezoneCache::TimeZoneDetection::value)); \
STATIC_ASSERT(static_cast<int>(v8::Isolate::TimeZoneDetection::value) == \
static_cast<int>(v8::Date::TimeZoneDetection::value));
TIME_ZONE_DETECTION_ASSERT_EQ(kSkip)
TIME_ZONE_DETECTION_ASSERT_EQ(kRedetect)
#undef TIME_ZONE_DETECTION_ASSERT_EQ
// static
void v8::Date::DateTimeConfigurationChangeNotification(
Isolate* isolate, TimeZoneDetection time_zone_detection) {
isolate->DateTimeConfigurationChangeNotification(
static_cast<v8::Isolate::TimeZoneDetection>(time_zone_detection));
}
MaybeLocal<v8::RegExp> v8::RegExp::New(Local<Context> context,
Local<String> pattern, Flags flags) {
PREPARE_FOR_EXECUTION(context, RegExp, New, RegExp);
@@ -9797,6 +9882,10 @@ int CpuProfile::GetSamplesCount() const {
return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
}
CpuProfiler* CpuProfiler::New(Isolate* isolate) {
return New(isolate, kDebugNaming);
}
CpuProfiler* CpuProfiler::New(Isolate* isolate, CpuProfilingNamingMode mode) {
return reinterpret_cast<CpuProfiler*>(
new i::CpuProfiler(reinterpret_cast<i::Isolate*>(isolate), mode));
@@ -9838,6 +9927,12 @@ void CpuProfiler::StartProfiling(Local<String> title, bool record_samples) {
*Utils::OpenHandle(*title), options);
}
void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
bool record_samples) {
StartProfiling(title, mode, record_samples,
CpuProfilingOptions::kNoSampleLimit);
}
void CpuProfiler::StartProfiling(Local<String> title, CpuProfilingMode mode,
bool record_samples, unsigned max_samples) {
CpuProfilingOptions options(mode, record_samples ? max_samples : 0);
+50 -7
View File
@@ -380,6 +380,10 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
Internals::kNodeStateMask);
STATIC_ASSERT(WEAK == Internals::kNodeStateIsWeakValue);
STATIC_ASSERT(PENDING == Internals::kNodeStateIsPendingValue);
STATIC_ASSERT(static_cast<int>(IsIndependent::kShift) ==
Internals::kNodeIsIndependentShift);
STATIC_ASSERT(static_cast<int>(IsActive::kShift) ==
Internals::kNodeIsActiveShift);
set_in_young_list(false);
}
@@ -399,6 +403,16 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
State state() const { return NodeState::decode(flags_); }
void set_state(State state) { flags_ = NodeState::update(flags_, state); }
bool is_independent() { return IsIndependent::decode(flags_); }
void set_independent(bool v) { flags_ = IsIndependent::update(flags_, v); }
bool is_active() {
return IsActive::decode(flags_);
}
void set_active(bool v) {
flags_ = IsActive::update(flags_, v);
}
bool is_in_young_list() const { return IsInYoungList::decode(flags_); }
void set_in_young_list(bool v) { flags_ = IsInYoungList::update(flags_, v); }
@@ -545,6 +559,7 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
// This method invokes a finalizer. Updating the method name would require
// adjusting CFI blacklist as weak_callback_ is invoked on the wrong type.
CHECK(IsPendingFinalizer());
CHECK(!is_active());
set_state(NEAR_DEATH);
// Check that we are not passing a finalized external string to
// the callback.
@@ -574,14 +589,25 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
private:
// Fields that are not used for managing node memory.
void ClearImplFields() { weak_callback_ = nullptr; }
void ClearImplFields() {
set_independent(false);
set_active(false);
weak_callback_ = nullptr;
}
void CheckImplFieldsAreCleared() { DCHECK_EQ(nullptr, weak_callback_); }
void CheckImplFieldsAreCleared() {
DCHECK(!is_independent());
DCHECK(!is_active());
DCHECK_EQ(nullptr, weak_callback_);
}
// This stores three flags (independent, partially_dependent and
// in_young_list) and a State.
class NodeState : public BitField8<State, 0, 3> {};
class IsInYoungList : public BitField8<bool, NodeState::kNext, 1> {};
class IsIndependent : public BitField8<bool, NodeState::kNext, 1> {};
// The following two fields are mutually exclusive
class IsActive : public BitField8<bool, IsIndependent::kNext, 1> {};
class IsInYoungList : public BitField8<bool, IsActive::kNext, 1> {};
class NodeWeaknessType
: public BitField8<WeaknessType, IsInYoungList::kNext, 2> {};
@@ -844,6 +870,12 @@ void GlobalHandles::IterateWeakRootsIdentifyFinalizers(
void GlobalHandles::IdentifyWeakUnmodifiedObjects(
WeakSlotCallback is_unmodified) {
for (Node* node : young_nodes_) {
if (node->IsWeak() && !is_unmodified(node->location())) {
node->set_active(true);
}
}
LocalEmbedderHeapTracer* const tracer =
isolate()->heap()->local_embedder_heap_tracer();
for (TracedNode* node : traced_young_nodes_) {
@@ -860,7 +892,9 @@ void GlobalHandles::IdentifyWeakUnmodifiedObjects(
void GlobalHandles::IterateYoungStrongAndDependentRoots(RootVisitor* v) {
for (Node* node : young_nodes_) {
if (node->IsStrongRetainer()) {
if (node->IsStrongRetainer() ||
(node->IsWeakRetainer() && !node->is_independent() &&
node->is_active())) {
v->VisitRootPointer(Root::kGlobalHandles, node->label(),
node->location());
}
@@ -876,7 +910,8 @@ void GlobalHandles::MarkYoungWeakUnmodifiedObjectsPending(
WeakSlotCallbackWithHeap is_dead) {
for (Node* node : young_nodes_) {
DCHECK(node->is_in_young_list());
if (node->IsWeak() && is_dead(isolate_->heap(), node->location())) {
if ((node->is_independent() || !node->is_active()) && node->IsWeak() &&
is_dead(isolate_->heap(), node->location())) {
if (!node->IsPhantomCallback() && !node->IsPhantomResetHandle()) {
node->MarkPending();
}
@@ -888,7 +923,8 @@ void GlobalHandles::IterateYoungWeakUnmodifiedRootsForFinalizers(
RootVisitor* v) {
for (Node* node : young_nodes_) {
DCHECK(node->is_in_young_list());
if (node->IsWeakRetainer() && (node->state() == Node::PENDING)) {
if ((node->is_independent() || !node->is_active()) &&
node->IsWeakRetainer() && (node->state() == Node::PENDING)) {
DCHECK(!node->IsPhantomCallback());
DCHECK(!node->IsPhantomResetHandle());
// Finalizers need to survive.
@@ -902,7 +938,8 @@ void GlobalHandles::IterateYoungWeakUnmodifiedRootsForPhantomHandles(
RootVisitor* v, WeakSlotCallbackWithHeap should_reset_handle) {
for (Node* node : young_nodes_) {
DCHECK(node->is_in_young_list());
if (node->IsWeakRetainer() && (node->state() != Node::PENDING)) {
if ((node->is_independent() || !node->is_active()) &&
node->IsWeakRetainer() && (node->state() != Node::PENDING)) {
if (should_reset_handle(isolate_->heap(), node->location())) {
DCHECK(node->IsPhantomResetHandle() || node->IsPhantomCallback());
if (node->IsPhantomResetHandle()) {
@@ -977,6 +1014,9 @@ size_t GlobalHandles::PostScavengeProcessing(unsigned post_processing_count) {
// Filter free nodes.
if (!node->IsRetainer()) continue;
// Reset active state for all affected nodes.
node->set_active(false);
if (node->IsPending()) {
DCHECK(node->has_callback());
DCHECK(node->IsPendingFinalizer());
@@ -995,6 +1035,9 @@ size_t GlobalHandles::PostMarkSweepProcessing(unsigned post_processing_count) {
// Filter free nodes.
if (!node->IsRetainer()) continue;
// Reset active state for all affected nodes.
node->set_active(false);
if (node->IsPending()) {
DCHECK(node->has_callback());
DCHECK(node->IsPendingFinalizer());
+10
View File
@@ -92,6 +92,16 @@ void SamplingHeapProfiler::SampleObject(Address soon_object, size_t size) {
base::make_unique<Sample>(size, node, loc, this, next_sample_id());
sample->global.SetWeak(sample.get(), OnWeakCallback,
WeakCallbackType::kParameter);
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
// MarkIndependent is marked deprecated but we still rely on it here
// temporarily.
sample->global.MarkIndependent();
#if __clang__
#pragma clang diagnostic pop
#endif
samples_.emplace(sample.get(), std::move(sample));
}
-16
View File
@@ -12,22 +12,6 @@ namespace v8 {
namespace internal {
namespace heap {
class TemporaryEmbedderHeapTracerScope {
public:
TemporaryEmbedderHeapTracerScope(v8::Isolate* isolate,
v8::EmbedderHeapTracer* tracer)
: isolate_(isolate) {
isolate_->SetEmbedderHeapTracer(tracer);
}
~TemporaryEmbedderHeapTracerScope() {
isolate_->SetEmbedderHeapTracer(nullptr);
}
private:
v8::Isolate* const isolate_;
};
void SealCurrentObjects(Heap* heap);
int FixedArrayLenFromSize(int size);
+31 -15
View File
@@ -103,6 +103,22 @@ class TestEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
v8::Global<v8::Array> array_;
};
class TemporaryEmbedderHeapTracerScope {
public:
TemporaryEmbedderHeapTracerScope(v8::Isolate* isolate,
EmbedderHeapTracer* tracer)
: isolate_(isolate) {
isolate_->SetEmbedderHeapTracer(tracer);
}
~TemporaryEmbedderHeapTracerScope() {
isolate_->SetEmbedderHeapTracer(nullptr);
}
private:
v8::Isolate* const isolate_;
};
} // namespace
TEST(V8RegisteringEmbedderReference) {
@@ -112,7 +128,7 @@ TEST(V8RegisteringEmbedderReference) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
@@ -132,7 +148,7 @@ TEST(EmbedderRegisteringV8Reference) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
@@ -165,7 +181,7 @@ TEST(TracingInRevivedSubgraph) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
@@ -193,7 +209,7 @@ TEST(TracingInEphemerons) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
@@ -224,7 +240,7 @@ TEST(FinalizeTracingIsNoopWhenNotMarking) {
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
// Finalize a potentially running garbage collection.
i_isolate->heap()->CollectGarbage(OLD_SPACE,
@@ -243,7 +259,7 @@ TEST(FinalizeTracingWhenMarking) {
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
// Finalize a potentially running garbage collection.
i_isolate->heap()->CollectGarbage(OLD_SPACE,
@@ -268,7 +284,7 @@ TEST(GarbageCollectionForTesting) {
v8::Isolate* isolate = CcTest::isolate();
Isolate* i_isolate = CcTest::i_isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
int saved_gc_counter = i_isolate->heap()->gc_count();
tracer.GarbageCollectionForTesting(EmbedderHeapTracer::kUnknown);
@@ -398,7 +414,7 @@ TEST(TracedGlobalToUnmodifiedJSObjectSurvivesScavengeWhenExcludedFromRoots) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
tracer.ConsiderTracedGlobalAsRoot(false);
TracedGlobalTest(
CcTest::isolate(), ConstructJSObject,
@@ -411,7 +427,7 @@ TEST(TracedGlobalToUnmodifiedJSApiObjectSurvivesScavengePerDefault) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
tracer.ConsiderTracedGlobalAsRoot(true);
TracedGlobalTest(
CcTest::isolate(), ConstructJSApiObject,
@@ -424,7 +440,7 @@ TEST(TracedGlobalToUnmodifiedJSApiObjectDiesOnScavengeWhenExcludedFromRoots) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
tracer.ConsiderTracedGlobalAsRoot(false);
TracedGlobalTest(
CcTest::isolate(), ConstructJSApiObject,
@@ -438,7 +454,7 @@ TEST(TracedGlobalWrapperClassId) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::TracedGlobal<v8::Object> traced;
ConstructJSObject(isolate, isolate->GetCurrentContext(), &traced);
@@ -473,7 +489,7 @@ TEST(TracedGlobalIteration) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::TracedGlobal<v8::Object> traced;
ConstructJSObject(isolate, isolate->GetCurrentContext(), &traced);
@@ -506,7 +522,7 @@ TEST(TracedGlobalSetFinalizationCallbackScavenge) {
v8::HandleScope scope(isolate);
TestEmbedderHeapTracer tracer;
tracer.ConsiderTracedGlobalAsRoot(false);
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::TracedGlobal<v8::Object> traced;
ConstructJSApiObject(isolate, isolate->GetCurrentContext(), &traced);
@@ -528,7 +544,7 @@ TEST(TracedGlobalSetFinalizationCallbackMarkSweep) {
v8::Isolate* isolate = CcTest::isolate();
v8::HandleScope scope(isolate);
TestEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
v8::TracedGlobal<v8::Object> traced;
ConstructJSApiObject(isolate, isolate->GetCurrentContext(), &traced);
@@ -558,7 +574,7 @@ TEST(TracePrologueCallingIntoV8WriteBarrier) {
}
TestEmbedderHeapTracer tracer(TracePrologueBehavior::kCallV8WriteBarrier,
std::move(global));
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
SimulateIncrementalMarking(CcTest::i_isolate()->heap());
}
+125
View File
@@ -496,6 +496,44 @@ static void TestWeakGlobalHandleCallback(
p->first->Reset();
}
TEST(WeakGlobalHandlesScavenge) {
FLAG_stress_compaction = false;
FLAG_stress_incremental_marking = false;
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
Factory* factory = isolate->factory();
GlobalHandles* global_handles = isolate->global_handles();
WeakPointerCleared = false;
Handle<Object> h1;
Handle<Object> h2;
{
HandleScope scope(isolate);
Handle<Object> i = factory->NewStringFromStaticChars("fisk");
Handle<Object> u = factory->NewNumber(1.12344);
h1 = global_handles->Create(*i);
h2 = global_handles->Create(*u);
}
std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
GlobalHandles::MakeWeak(
h2.location(), reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback, v8::WeakCallbackType::kParameter);
// Scavenge treats weak pointers as normal roots.
CcTest::CollectGarbage(NEW_SPACE);
CHECK((*h1).IsString());
CHECK((*h2).IsHeapNumber());
CHECK(!WeakPointerCleared);
GlobalHandles::Destroy(h1.location());
GlobalHandles::Destroy(h2.location());
}
TEST(WeakGlobalUnmodifiedApiHandlesScavenge) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
@@ -534,6 +572,84 @@ TEST(WeakGlobalUnmodifiedApiHandlesScavenge) {
GlobalHandles::Destroy(h1.location());
}
TEST(WeakGlobalApiHandleModifiedMapScavenge) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
LocalContext context;
GlobalHandles* global_handles = isolate->global_handles();
WeakPointerCleared = false;
Handle<Object> h1;
{
HandleScope scope(isolate);
// Create an API object which does not have the same map as constructor.
auto function_template = FunctionTemplate::New(context->GetIsolate());
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(v8::String::NewFromUtf8(context->GetIsolate(), "a",
NewStringType::kNormal)
.ToLocalChecked(),
v8::Number::New(context->GetIsolate(), 10));
auto function =
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
h1 = global_handles->Create(*(reinterpret_cast<internal::Address*>(*i)));
}
std::pair<Handle<Object>*, int> handle_and_id(&h1, 1234);
GlobalHandles::MakeWeak(
h1.location(), reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback, v8::WeakCallbackType::kParameter);
CcTest::CollectGarbage(NEW_SPACE);
CHECK(!WeakPointerCleared);
GlobalHandles::Destroy(h1.location());
}
TEST(WeakGlobalApiHandleWithElementsScavenge) {
CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate();
LocalContext context;
GlobalHandles* global_handles = isolate->global_handles();
WeakPointerCleared = false;
Handle<Object> h1;
{
HandleScope scope(isolate);
// Create an API object which has elements.
auto function_template = FunctionTemplate::New(context->GetIsolate());
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(v8::String::NewFromUtf8(context->GetIsolate(), "1",
NewStringType::kNormal)
.ToLocalChecked(),
v8::Number::New(context->GetIsolate(), 10));
instance_t->Set(v8::String::NewFromUtf8(context->GetIsolate(), "2",
NewStringType::kNormal)
.ToLocalChecked(),
v8::Number::New(context->GetIsolate(), 10));
auto function =
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
h1 = global_handles->Create(*(reinterpret_cast<internal::Address*>(*i)));
}
std::pair<Handle<Object>*, int> handle_and_id(&h1, 1234);
GlobalHandles::MakeWeak(
h1.location(), reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback, v8::WeakCallbackType::kParameter);
CcTest::CollectGarbage(NEW_SPACE);
CHECK(!WeakPointerCleared);
GlobalHandles::Destroy(h1.location());
}
TEST(WeakGlobalHandlesMark) {
FLAG_stress_incremental_marking = false;
CcTest::InitializeVM();
@@ -583,7 +699,9 @@ TEST(DeleteWeakGlobalHandle) {
GlobalHandles* global_handles = isolate->global_handles();
WeakPointerCleared = false;
Handle<Object> h;
{
HandleScope scope(isolate);
@@ -595,8 +713,15 @@ TEST(DeleteWeakGlobalHandle) {
GlobalHandles::MakeWeak(h.location(), reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback,
v8::WeakCallbackType::kParameter);
// Scanvenge does not recognize weak reference.
CcTest::CollectGarbage(NEW_SPACE);
CHECK(!WeakPointerCleared);
// Mark-compact treats weak reference properly.
CcTest::CollectGarbage(OLD_SPACE);
CHECK(WeakPointerCleared);
}
+35
View File
@@ -7628,6 +7628,18 @@ static void IndependentWeakHandle(bool global_gc, bool interlinked) {
v8::WeakCallbackType::kParameter);
object_b.handle.SetWeak(&object_b, &SetFlag,
v8::WeakCallbackType::kParameter);
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
// MarkIndependent is marked deprecated but we still rely on it temporarily.
CHECK(!object_b.handle.IsIndependent());
object_a.handle.MarkIndependent();
object_b.handle.MarkIndependent();
CHECK(object_b.handle.IsIndependent());
#if __clang__
#pragma clang diagnostic pop
#endif
if (global_gc) {
CcTest::CollectAllGarbage();
} else {
@@ -7778,6 +7790,19 @@ void v8::internal::heap::HeapTester::ResetWeakHandle(bool global_gc) {
v8::WeakCallbackType::kParameter);
object_b.handle.SetWeak(&object_b, &ResetUseValueAndSetFlag,
v8::WeakCallbackType::kParameter);
if (!global_gc) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
// MarkIndependent is marked deprecated but we still rely on it temporarily.
object_a.handle.MarkIndependent();
object_b.handle.MarkIndependent();
CHECK(object_b.handle.IsIndependent());
#if __clang__
#pragma clang diagnostic pop
#endif
}
if (global_gc) {
CcTest::PreciseCollectAllGarbage();
} else {
@@ -7845,6 +7870,16 @@ THREADED_TEST(GCFromWeakCallbacks) {
object.flag = false;
object.handle.SetWeak(&object, gc_forcing_callback[inner_gc],
v8::WeakCallbackType::kParameter);
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
// MarkIndependent is marked deprecated but we still rely on it
// temporarily.
object.handle.MarkIndependent();
#if __clang__
#pragma clang diagnostic pop
#endif
invoke_gc[outer_gc]();
EmptyMessageQueues(isolate);
CHECK(object.flag);
+88 -152
View File
@@ -39,25 +39,6 @@ namespace internal {
namespace {
// Empty v8::EmbedderHeapTracer that never keeps objects alive on Scavenge. See
// |IsRootForNonTracingGC|.
class NonRootingEmbedderHeapTracer final : public v8::EmbedderHeapTracer {
public:
NonRootingEmbedderHeapTracer() = default;
void RegisterV8References(
const std::vector<std::pair<void*, void*>>& embedder_fields) final {}
bool AdvanceTracing(double deadline_in_ms) final { return true; }
bool IsTracingDone() final { return true; }
void TracePrologue() final {}
void TraceEpilogue() final {}
void EnterFinalPause(EmbedderStackState) final {}
bool IsRootForNonTracingGC(const v8::TracedGlobal<v8::Value>& handle) final {
return false;
}
};
void InvokeScavenge() { CcTest::CollectGarbage(i::NEW_SPACE); }
void InvokeMarkSweep() { CcTest::CollectAllGarbage(); }
@@ -66,23 +47,23 @@ void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(v8_num(0));
}
struct FlagAndGlobal {
struct FlagAndPersistent {
bool flag;
v8::Global<v8::Object> handle;
};
struct TracedGlobalWrapper {
v8::TracedGlobal<v8::Object> handle;
};
void ResetHandleAndSetFlag(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void ResetHandleAndSetFlag(
const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->handle.Reset();
data.GetParameter()->flag = true;
}
template <typename HandleContainer>
using ConstructFunction = void (*)(v8::Isolate* isolate,
v8::Local<v8::Context> context,
FlagAndPersistent* flag_and_persistent);
void ConstructJSObject(v8::Isolate* isolate, v8::Local<v8::Context> context,
HandleContainer* flag_and_persistent) {
FlagAndPersistent* flag_and_persistent) {
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Object> object(v8::Object::New(isolate));
CHECK(!object.IsEmpty());
@@ -98,9 +79,8 @@ void ConstructJSObject(v8::Isolate* isolate, v8::Global<v8::Object>* global) {
CHECK(!global->IsEmpty());
}
template <typename HandleContainer>
void ConstructJSApiObject(v8::Isolate* isolate, v8::Local<v8::Context> context,
HandleContainer* flag_and_persistent) {
FlagAndPersistent* flag_and_persistent) {
v8::HandleScope handle_scope(isolate);
v8::Local<v8::FunctionTemplate> fun =
v8::FunctionTemplate::New(isolate, SimpleCallback);
@@ -115,8 +95,7 @@ void ConstructJSApiObject(v8::Isolate* isolate, v8::Local<v8::Context> context,
enum class SurvivalMode { kSurvives, kDies };
template <typename ConstructFunction, typename ModifierFunction,
typename GCFunction>
template <typename ModifierFunction, typename GCFunction>
void WeakHandleTest(v8::Isolate* isolate, ConstructFunction construct_function,
ModifierFunction modifier_function, GCFunction gc_function,
SurvivalMode survives) {
@@ -124,7 +103,7 @@ void WeakHandleTest(v8::Isolate* isolate, ConstructFunction construct_function,
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
FlagAndGlobal fp;
FlagAndPersistent fp;
construct_function(isolate, context, &fp);
CHECK(heap::InYoungGeneration(isolate, fp.handle));
fp.handle.SetWeak(&fp, &ResetHandleAndSetFlag,
@@ -136,28 +115,6 @@ void WeakHandleTest(v8::Isolate* isolate, ConstructFunction construct_function,
CHECK_IMPLIES(survives == SurvivalMode::kDies, fp.flag);
}
template <typename ConstructFunction, typename ModifierFunction,
typename GCFunction>
void TracedGlobalTest(v8::Isolate* isolate,
ConstructFunction construct_function,
ModifierFunction modifier_function,
GCFunction gc_function, SurvivalMode survives) {
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
NonRootingEmbedderHeapTracer tracer;
heap::TemporaryEmbedderHeapTracerScope tracer_scope(isolate, &tracer);
TracedGlobalWrapper fp;
construct_function(isolate, context, &fp);
CHECK(heap::InYoungGeneration(isolate, fp.handle));
modifier_function(&fp);
gc_function();
CHECK_IMPLIES(survives == SurvivalMode::kSurvives, !fp.handle.IsEmpty());
CHECK_IMPLIES(survives == SurvivalMode::kDies, fp.handle.IsEmpty());
}
void ResurrectingFinalizer(
const v8::WeakCallbackInfo<v8::Global<v8::Object>>& data) {
data.GetParameter()->ClearWeak();
@@ -320,36 +277,25 @@ TEST(PhatomHandlesWithoutCallbacks) {
CHECK_EQ(0u, isolate->NumberOfPhantomHandleResetsSinceLastCall());
}
TEST(WeakHandleToUnmodifiedJSObjectDiesOnScavenge) {
TEST(WeakHandleToUnmodifiedJSObjectSurvivesScavenge) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeScavenge(); },
SurvivalMode::kDies);
}
TEST(TracedGlobalToUnmodifiedJSObjectSurvivesScavenge) {
ManualGCScope manual_gc;
CcTest::InitializeVM();
TracedGlobalTest(
CcTest::isolate(), &ConstructJSObject<TracedGlobalWrapper>,
[](TracedGlobalWrapper* fp) {}, []() { InvokeScavenge(); },
SurvivalMode::kSurvives);
CcTest::isolate(), &ConstructJSObject, [](FlagAndPersistent* fp) {},
[]() { InvokeScavenge(); }, SurvivalMode::kSurvives);
}
TEST(WeakHandleToUnmodifiedJSObjectDiesOnMarkCompact) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeMarkSweep(); },
SurvivalMode::kDies);
CcTest::isolate(), &ConstructJSObject, [](FlagAndPersistent* fp) {},
[]() { InvokeMarkSweep(); }, SurvivalMode::kDies);
}
TEST(WeakHandleToUnmodifiedJSObjectSurvivesMarkCompactWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {
CcTest::isolate(), &ConstructJSObject,
[](FlagAndPersistent* fp) {
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
@@ -360,30 +306,19 @@ TEST(WeakHandleToUnmodifiedJSObjectSurvivesMarkCompactWhenInHandle) {
TEST(WeakHandleToUnmodifiedJSApiObjectDiesOnScavenge) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeScavenge(); },
SurvivalMode::kDies);
CcTest::isolate(), &ConstructJSApiObject, [](FlagAndPersistent* fp) {},
[]() { InvokeScavenge(); }, SurvivalMode::kDies);
}
TEST(TracedGlobalToUnmodifiedJSApiObjectDiesOnScavenge) {
ManualGCScope manual_gc;
CcTest::InitializeVM();
TracedGlobalTest(
CcTest::isolate(), &ConstructJSApiObject<TracedGlobalWrapper>,
[](TracedGlobalWrapper* fp) {}, []() { InvokeScavenge(); },
SurvivalMode::kDies);
}
TEST(TracedGlobalToJSApiObjectWithIdentityHashSurvivesScavenge) {
ManualGCScope manual_gc;
TEST(WeakHandleToJSApiObjectWithIdentityHashSurvivesScavenge) {
CcTest::InitializeVM();
Isolate* i_isolate = CcTest::i_isolate();
HandleScope scope(i_isolate);
Handle<JSWeakMap> weakmap = i_isolate->factory()->NewJSWeakMap();
TracedGlobalTest(
CcTest::isolate(), &ConstructJSApiObject<TracedGlobalWrapper>,
[&weakmap, i_isolate](TracedGlobalWrapper* fp) {
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject,
[&weakmap, i_isolate](FlagAndPersistent* fp) {
v8::HandleScope scope(CcTest::isolate());
Handle<JSReceiver> key =
Utils::OpenHandle(*fp->handle.Get(CcTest::isolate()));
@@ -397,8 +332,8 @@ TEST(TracedGlobalToJSApiObjectWithIdentityHashSurvivesScavenge) {
TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesScavengeWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {
CcTest::isolate(), &ConstructJSApiObject,
[](FlagAndPersistent* fp) {
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
@@ -409,16 +344,15 @@ TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesScavengeWhenInHandle) {
TEST(WeakHandleToUnmodifiedJSApiObjectDiesOnMarkCompact) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {}, []() { InvokeMarkSweep(); },
SurvivalMode::kDies);
CcTest::isolate(), &ConstructJSApiObject, [](FlagAndPersistent* fp) {},
[]() { InvokeMarkSweep(); }, SurvivalMode::kDies);
}
TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesMarkCompactWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject<FlagAndGlobal>,
[](FlagAndGlobal* fp) {
CcTest::isolate(), &ConstructJSApiObject,
[](FlagAndPersistent* fp) {
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
@@ -426,57 +360,58 @@ TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesMarkCompactWhenInHandle) {
[]() { InvokeMarkSweep(); }, SurvivalMode::kSurvives);
}
TEST(TracedGlobalToJSApiObjectWithModifiedMapSurvivesScavenge) {
TEST(WeakHandleToActiveUnmodifiedJSApiObjectSurvivesScavenge) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
LocalContext context;
TracedGlobal<v8::Object> handle;
{
v8::HandleScope scope(isolate);
// Create an API object which does not have the same map as constructor.
auto function_template = FunctionTemplate::New(isolate);
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(
v8::String::NewFromUtf8(isolate, "a", NewStringType::kNormal)
.ToLocalChecked(),
v8::Number::New(isolate, 10));
auto function =
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
handle.Reset(isolate, i);
}
InvokeScavenge();
CHECK(!handle.IsEmpty());
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject,
[](FlagAndPersistent* fp) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
fp->handle.MarkActive();
#if __clang__
#pragma clang diagnostic pop
#endif
},
[]() { InvokeScavenge(); }, SurvivalMode::kSurvives);
}
TEST(TracedGlobalTOJsApiObjectWithElementsSurvivesScavenge) {
TEST(WeakHandleToActiveUnmodifiedJSApiObjectDiesOnMarkCompact) {
CcTest::InitializeVM();
v8::Isolate* isolate = CcTest::isolate();
LocalContext context;
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject,
[](FlagAndPersistent* fp) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
fp->handle.MarkActive();
#if __clang__
#pragma clang diagnostic pop
#endif
},
[]() { InvokeMarkSweep(); }, SurvivalMode::kDies);
}
TracedGlobal<v8::Object> handle;
{
v8::HandleScope scope(isolate);
// Create an API object which has elements.
auto function_template = FunctionTemplate::New(isolate);
auto instance_t = function_template->InstanceTemplate();
instance_t->Set(
v8::String::NewFromUtf8(isolate, "1", NewStringType::kNormal)
.ToLocalChecked(),
v8::Number::New(isolate, 10));
instance_t->Set(
v8::String::NewFromUtf8(isolate, "2", NewStringType::kNormal)
.ToLocalChecked(),
v8::Number::New(isolate, 10));
auto function =
function_template->GetFunction(context.local()).ToLocalChecked();
auto i = function->NewInstance(context.local()).ToLocalChecked();
handle.Reset(isolate, i);
}
InvokeScavenge();
CHECK(!handle.IsEmpty());
TEST(WeakHandleToActiveUnmodifiedJSApiObjectSurvivesMarkCompactWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject,
[](FlagAndPersistent* fp) {
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#endif
fp->handle.MarkActive();
#if __clang__
#pragma clang diagnostic pop
#endif
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
USE(handle);
},
[]() { InvokeMarkSweep(); }, SurvivalMode::kSurvives);
}
TEST(FinalizerOnUnmodifiedJSApiObjectDoesNotCrash) {
@@ -487,7 +422,8 @@ TEST(FinalizerOnUnmodifiedJSApiObjectDoesNotCrash) {
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
FlagAndGlobal fp;
FlagAndPersistent fp;
// Could use a regular object and MarkIndependent too.
ConstructJSApiObject(isolate, context, &fp);
fp.handle.SetWeak(&fp, &ResetHandleAndSetFlag,
v8::WeakCallbackType::kFinalizer);
@@ -559,22 +495,22 @@ TEST(FinalizerDiesAndKeepsPhantomAliveOnMarkCompact) {
namespace {
void ForceScavenge2(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void ForceScavenge2(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->flag = true;
InvokeScavenge();
}
void ForceScavenge1(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void ForceScavenge1(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->handle.Reset();
data.SetSecondPassCallback(ForceScavenge2);
}
void ForceMarkSweep2(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void ForceMarkSweep2(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->flag = true;
InvokeMarkSweep();
}
void ForceMarkSweep1(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void ForceMarkSweep1(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->handle.Reset();
data.SetSecondPassCallback(ForceMarkSweep2);
}
@@ -589,7 +525,7 @@ TEST(GCFromWeakCallbacks) {
v8::Context::Scope context_scope(context);
static const int kNumberOfGCTypes = 2;
using Callback = v8::WeakCallbackInfo<FlagAndGlobal>::Callback;
typedef v8::WeakCallbackInfo<FlagAndPersistent>::Callback Callback;
Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1,
&ForceMarkSweep1};
@@ -598,7 +534,7 @@ TEST(GCFromWeakCallbacks) {
for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
FlagAndGlobal fp;
FlagAndPersistent fp;
ConstructJSApiObject(isolate, context, &fp);
CHECK(heap::InYoungGeneration(isolate, fp.handle));
fp.flag = false;
@@ -613,11 +549,11 @@ TEST(GCFromWeakCallbacks) {
namespace {
void SecondPassCallback(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void SecondPassCallback(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->flag = true;
}
void FirstPassCallback(const v8::WeakCallbackInfo<FlagAndGlobal>& data) {
void FirstPassCallback(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
data.GetParameter()->handle.Reset();
data.SetSecondPassCallback(SecondPassCallback);
}
@@ -630,7 +566,7 @@ TEST(SecondPassPhantomCallbacks) {
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
FlagAndGlobal fp;
FlagAndPersistent fp;
ConstructJSApiObject(isolate, context, &fp);
fp.flag = false;
fp.handle.SetWeak(&fp, FirstPassCallback, v8::WeakCallbackType::kParameter);