Skip to content

Commit 42c82fe

Browse files
committed
[wip] changes to support Node.js v16
This isn't quite ready for review yet, I just want to get it out there so people can see that progress is being made. The biggest problem currently is that this currently breaks support for Node.js v14. With this diff, our tests are much better. Previously they were entirely failing on Node 16. Now: * `stack-test` passes (12/12) * `inspect-test` mostly passes (55/59) * `frame-test` somewhat passes (7/25) There are a lot of changes in this diff. I plan on splitting the commits before the review, but here's a summary of the changes: 1. `ScopeInfo` is no longer a `FixedArray` as of v8/v8@ecaac329. The `Length` field was also removed in v8/v8@f731e13f. - The length field shifted everything over by a slot, meaning that a bunch of offsets changed. - Since `ScopeInfo` is no longer a `FixedArray`, I changed callsites to use `HeapObject::LoadFieldValue` rather than `FixedArray::Get`. 2. Changes to V8 calling conventions - The arguments adaptor frame no longer exists. Modified `frame-test.js` to match. - Arguments are no longer pushed "in reverse". Modified `JSFrame::LeaParamSlot` to match. 3. Postmortem data fixes - `class_Map__constructor_or_backpointer__Object` is now `class_Map__constructor_or_back_pointer__Object` (note the extra `_`). - `class_Script__source__Object` is weirdly _not_ present in Node 16 but _is_ present in both Node 14 and Node 18. I added a default to the correct value of 8.
1 parent 39b38a9 commit 42c82fe

File tree

5 files changed

+53
-37
lines changed

5 files changed

+53
-37
lines changed

src/llv8-constants.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void Map::Load() {
9393
kMaybeConstructorOffset =
9494
LoadConstant("class_Map__constructor_or_backpointer__Object",
9595
"class_Map__constructor__Object");
96+
if (kMaybeConstructorOffset == -1) {
97+
kMaybeConstructorOffset =
98+
LoadConstant("class_Map__constructor_or_back_pointer__Object");
99+
}
100+
96101
kInstanceDescriptorsOffset = LoadConstant({
97102
"class_Map__instance_descriptors__DescriptorArray",
98103
"class_Map__instance_descriptors_offset",
@@ -300,7 +305,7 @@ void Context::Load() {
300305
void Script::Load() {
301306
kNameOffset = LoadConstant("class_Script__name__Object");
302307
kLineOffsetOffset = LoadConstant("class_Script__line_offset__SMI");
303-
kSourceOffset = LoadConstant("class_Script__source__Object");
308+
kSourceOffset = LoadConstant("class_Script__source__Object", 8);
304309
kLineEndsOffset = LoadConstant("class_Script__line_ends__Object");
305310
}
306311

src/llv8-inl.h

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ inline JSFunction JSFrame::GetFunction(Error& err) {
229229

230230
inline int64_t JSFrame::LeaParamSlot(int slot, int count) const {
231231
return raw() + v8()->frame()->kArgsOffset +
232-
(count - slot - 1) * v8()->common()->kPointerSize;
232+
(slot + 1) * v8()->common()->kPointerSize;
233233
}
234234

235235

@@ -483,7 +483,7 @@ inline CheckedType<int32_t> String::Length(Error& err) {
483483

484484
ACCESSOR(Script, Name, script()->kNameOffset, String)
485485
ACCESSOR(Script, LineOffset, script()->kLineOffsetOffset, Smi)
486-
ACCESSOR(Script, Source, script()->kSourceOffset, HeapObject)
486+
ACCESSOR(Script, Source, script()->kSourceOffset, String)
487487
ACCESSOR(Script, LineEnds, script()->kLineEndsOffset, HeapObject)
488488

489489
ACCESSOR(SharedFunctionInfo, function_data, shared_info()->kFunctionDataOffset,
@@ -722,21 +722,24 @@ inline CheckedType<uintptr_t> JSTypedArray::GetData() {
722722
inline ScopeInfo::PositionInfo ScopeInfo::MaybePositionInfo(Error& err) {
723723
ScopeInfo::PositionInfo position_info = {
724724
.start_position = 0, .end_position = 0, .is_valid = false};
725-
int proper_index = ContextLocalIndex(err);
725+
auto kPointerSize = v8()->common()->kPointerSize;
726+
int bytes_offset = kPointerSize * ContextLocalIndex(err);
726727
if (err.Fail()) return position_info;
727728

728729
Smi context_local_count = ContextLocalCount(err);
729730
if (err.Fail()) return position_info;
730-
proper_index += context_local_count.GetValue() * 2;
731+
bytes_offset += 2 * kPointerSize * context_local_count.GetValue();
731732

732733
int tries = 5;
733-
while (tries > 0 && proper_index < (Length(err).GetValue() - 1)) {
734+
while (tries > 0) {
734735
err = Error();
735736

736-
Smi maybe_start_position = Get<Smi>(proper_index, err);
737+
Smi maybe_start_position =
738+
HeapObject::LoadFieldValue<Smi>(bytes_offset, err);
737739
if (err.Success() && maybe_start_position.IsSmi(err)) {
738-
proper_index++;
739-
Smi maybe_end_position = Get<Smi>(proper_index, err);
740+
bytes_offset += kPointerSize;
741+
Smi maybe_end_position =
742+
HeapObject::LoadFieldValue<Smi>(bytes_offset, err);
740743
if (err.Success() && maybe_end_position.IsSmi(err)) {
741744
position_info.start_position = maybe_start_position.GetValue();
742745
position_info.end_position = maybe_end_position.GetValue();
@@ -746,7 +749,7 @@ inline ScopeInfo::PositionInfo ScopeInfo::MaybePositionInfo(Error& err) {
746749
}
747750

748751
tries--;
749-
proper_index++;
752+
bytes_offset += kPointerSize;
750753
}
751754
return position_info;
752755
}
@@ -1091,19 +1094,26 @@ inline Value Context::ContextSlot(int index, Error& err) {
10911094
}
10921095

10931096
inline Smi ScopeInfo::ParameterCount(Error& err) {
1094-
return FixedArray::Get<Smi>(v8()->scope_info()->kParameterCountOffset, err);
1097+
Smi res = HeapObject::LoadFieldValue<Smi>(
1098+
v8()->scope_info()->kParameterCountOffset * v8()->common()->kPointerSize,
1099+
err);
1100+
return res;
10951101
}
10961102

10971103
inline Smi ScopeInfo::StackLocalCount(Error& err) {
10981104
if (v8()->scope_info()->kStackLocalCountOffset == -1) {
10991105
return Smi(v8(), 0);
11001106
}
1101-
return FixedArray::Get<Smi>(v8()->scope_info()->kStackLocalCountOffset, err);
1107+
return HeapObject::LoadFieldValue<Smi>(
1108+
v8()->scope_info()->kStackLocalCountOffset * v8()->common()->kPointerSize,
1109+
err);
11021110
}
11031111

11041112
inline Smi ScopeInfo::ContextLocalCount(Error& err) {
1105-
return FixedArray::Get<Smi>(v8()->scope_info()->kContextLocalCountOffset,
1106-
err);
1113+
return HeapObject::LoadFieldValue<Smi>(
1114+
(v8()->scope_info()->kContextLocalCountOffset + 1) *
1115+
v8()->common()->kPointerSize,
1116+
err);
11071117
}
11081118

11091119
inline int ScopeInfo::ContextLocalIndex(Error& err) {
@@ -1122,30 +1132,32 @@ inline int ScopeInfo::ContextLocalIndex(Error& err) {
11221132
}
11231133

11241134
inline String ScopeInfo::ContextLocalName(int index, Error& err) {
1125-
int proper_index = ContextLocalIndex(err) + index;
1135+
int proper_index =
1136+
(ContextLocalIndex(err) + index + 1) * v8()->common()->kPointerSize;
11261137
if (err.Fail()) return String();
1127-
return FixedArray::Get<String>(proper_index, err);
1138+
return HeapObject::LoadFieldValue<String>(proper_index, err);
11281139
}
11291140

11301141
inline HeapObject ScopeInfo::MaybeFunctionName(Error& err) {
1131-
int proper_index = ContextLocalIndex(err);
1132-
if (err.Fail()) return HeapObject();
1133-
1134-
Smi context_local_count = ContextLocalCount(err);
1135-
if (err.Fail()) return HeapObject();
1136-
proper_index += context_local_count.GetValue() * 2;
1137-
11381142
// NOTE(mmarchini): FunctionName can be stored either in the first, second or
11391143
// third slot after ContextLocalCount. Since there are missing postmortem
11401144
// metadata to determine in which slot its being stored for the present
11411145
// ScopeInfo, we try to find it heuristically.
1142-
int tries = 3;
1146+
auto kPointerSize = v8()->common()->kPointerSize;
11431147
HeapObject likely_function_name;
1144-
while (tries > 0 && proper_index < Length(err).GetValue()) {
1148+
int bytes_offset = kPointerSize * ContextLocalIndex(err);
1149+
if (err.Fail()) return likely_function_name;
1150+
1151+
Smi context_local_count = ContextLocalCount(err);
1152+
if (err.Fail()) return likely_function_name;
1153+
bytes_offset += 2 * kPointerSize * context_local_count.GetValue();
1154+
1155+
int tries = 5;
1156+
while (tries > 0) {
11451157
err = Error();
11461158

11471159
HeapObject maybe_function_name =
1148-
FixedArray::Get<HeapObject>(proper_index, err);
1160+
HeapObject::LoadFieldValue<HeapObject>(bytes_offset, err);
11491161
if (err.Success() && String::IsString(v8(), maybe_function_name, err)) {
11501162
likely_function_name = maybe_function_name;
11511163
if (*String(likely_function_name).Length(err) > 0) {
@@ -1154,7 +1166,7 @@ inline HeapObject ScopeInfo::MaybeFunctionName(Error& err) {
11541166
}
11551167

11561168
tries--;
1157-
proper_index++;
1169+
bytes_offset += kPointerSize;
11581170
}
11591171

11601172
if (likely_function_name.Check()) {

src/llv8.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void Script::GetLineColumnFromPos(int64_t pos, int64_t& line, int64_t& column,
484484
line = 0;
485485
column = 0;
486486

487-
HeapObject source = Source(err);
487+
String source = Source(err);
488488
if (err.Fail()) return;
489489

490490
int64_t type = source.GetType(err);
@@ -496,8 +496,7 @@ void Script::GetLineColumnFromPos(int64_t pos, int64_t& line, int64_t& column,
496496
return;
497497
}
498498

499-
String str(source);
500-
std::string source_str = str.ToString(err);
499+
std::string source_str = source.ToString(err);
501500
int64_t limit = source_str.length();
502501
if (limit > pos) limit = pos;
503502

src/llv8.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Script : public HeapObject {
182182

183183
inline String Name(Error& err);
184184
inline Smi LineOffset(Error& err);
185-
inline HeapObject Source(Error& err);
185+
inline String Source(Error& err);
186186
inline HeapObject LineEnds(Error& err);
187187

188188
void GetLines(uint64_t start_line, std::string lines[], uint64_t line_limit,
@@ -509,9 +509,9 @@ class NameDictionary : public FixedArray {
509509
inline int64_t Length(Error& err);
510510
};
511511

512-
class ScopeInfo : public FixedArray {
512+
class ScopeInfo : public HeapObject {
513513
public:
514-
V8_VALUE_DEFAULT_METHODS(ScopeInfo, FixedArray)
514+
V8_VALUE_DEFAULT_METHODS(ScopeInfo, HeapObject)
515515

516516
struct PositionInfo {
517517
int64_t start_position;

test/plugin/frame-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ tape('v8 stack', async (t) => {
7878
t.ok(lines.length > 4, 'frame count');
7979

8080
lines = lines.filter((s) => !/<builtin>|<stub>/.test(s));
81-
const exit = lines[5];
82-
const crasher = lines[4];
83-
const adapter = lines[3];
81+
const exit = lines[4];
82+
const crasher = lines[3];
8483
const fnInferredName = lines[2];
8584
const fnInferredNamePrototype = lines[1];
8685
const fnFunctionName = lines[0];
8786
t.ok(/<exit>/.test(exit), 'exit frame');
8887
t.ok(/crasher/.test(crasher), 'crasher frame');
89-
t.ok(/<adaptor>/.test(adapter), 'arguments adapter frame');
88+
if (nodejsVersion()[0] < 16)
89+
t.ok(/<adaptor>/.test(adapter), 'arguments adapter frame');
9090
if (nodejsVersion()[0] < 12)
9191
t.ok(/\sfnInferredName\(/.test(fnInferredName), 'fnInferredName frame');
9292
t.ok(/\sModule.fnInferredNamePrototype\(/.test(fnInferredNamePrototype),

0 commit comments

Comments
 (0)