Skip to content

Commit 4370850

Browse files
committed
illumos additions to IBM fix
1 parent eeee442 commit 4370850

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

deps/v8/src/codegen/code-stub-assembler.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,14 @@ TNode<Code> CodeStubAssembler::LoadCodeObjectFromJSDispatchTable(
19951995
shifted_value =
19961996
WordShr(value, UintPtrConstant(JSDispatchEntry::kObjectPointerShift));
19971997
} else {
1998+
#if defined(__illumos__) && defined(V8_HOST_ARCH_64_BIT)
1999+
// See VA hole discussion in js-dispatch-table.h
2000+
if (value < UintPtrConstant(0x8000000000000000ull)) // Below the VA hole
2001+
// I hope WordShr is unsigned...
2002+
shifted_value = WordShr(value,
2003+
UintPtrConstant(JSDispatchEntry::kObjectPointerShift));
2004+
else
2005+
#endif /* __illumos__ */
19982006
shifted_value = UintPtrAdd(
19992007
WordShr(value, UintPtrConstant(JSDispatchEntry::kObjectPointerShift)),
20002008
UintPtrConstant(JSDispatchEntry::kObjectPointerOffset));

deps/v8/src/sandbox/js-dispatch-table-inl.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ void JSDispatchEntry::MakeJSDispatchEntry(Address object, Address entrypoint,
2323
uint16_t parameter_count,
2424
bool mark_as_alive) {
2525
DCHECK_EQ(object & kHeapObjectTag, 0);
26+
#if defined(__illumos__) && defined(V8_TARGET_ARCH_64_BIT)
27+
// See VA hole discussion in js-dispatch-table.h
28+
if (((uintptr_t)object >> 47) != 0) {
29+
// Above VA hole.
30+
// If illumos changes the VA hole, this may have to be revisited.
31+
CHECK_EQ((object & 0xffff800000000000ull), 0xffff800000000000ull);
32+
} // Else implies addr is below the VA hole.
33+
34+
Address payload = (object << kObjectPointerShift) |
35+
(parameter_count & kParameterCountMask);
36+
#else
2637
DCHECK_EQ((((object - kObjectPointerOffset) << kObjectPointerShift) >>
2738
kObjectPointerShift) +
2839
kObjectPointerOffset,
@@ -33,6 +44,7 @@ void JSDispatchEntry::MakeJSDispatchEntry(Address object, Address entrypoint,
3344

3445
Address payload = ((object - kObjectPointerOffset) << kObjectPointerShift) |
3546
(parameter_count & kParameterCountMask);
47+
#endif /* __illumos__ 64-bit */
3648
DCHECK(!(payload & kMarkingBit));
3749
if (mark_as_alive) payload |= kMarkingBit;
3850
#ifdef V8_TARGET_ARCH_32_BIT
@@ -55,6 +67,14 @@ Address JSDispatchEntry::GetCodePointer() const {
5567
// and so may be 0 or 1 here. As the return value is a tagged pointer, the
5668
// bit must be 1 when returned, so we need to set it here.
5769
Address payload = encoded_word_.load(std::memory_order_relaxed);
70+
#if defined(__illumos__) && defined(V8_TARGET_ARCH_64_BIT)
71+
// illumos has two values for the higher bits, aka kObjectPointerOffset.
72+
// Lucky us, they are determined by the value of the highest bit in payload,
73+
// and one of them (below the VA hole) is 0.
74+
if (payload < 0x8000000000000000)
75+
return ((payload >> kObjectPointerShift) | kHeapObjectTag);
76+
// Else we continue, and the pointer is above the VA hole.
77+
#endif /* __illumos__ */
5878
return ((payload >> kObjectPointerShift) + kObjectPointerOffset) |
5979
kHeapObjectTag;
6080
}
@@ -183,11 +203,22 @@ void JSDispatchEntry::SetCodeAndEntrypointPointer(Address new_object,
183203
Address old_payload = encoded_word_.load(std::memory_order_relaxed);
184204
Address marking_bit = old_payload & kMarkingBit;
185205
Address parameter_count = old_payload & kParameterCountMask;
206+
#if defined(__illumos__) && defined(V8_TARGET_ARCH_64_BIT)
207+
// See VA hole discussion in js-dispatch-table.h
208+
if (((uintptr_t)new_object >> 47) != 0) {
209+
// Above VA hole.
210+
// If illumos changes the VA hole, this may have to be revisited.
211+
CHECK_EQ((new_object & 0xffff800000000000ull), 0xffff800000000000ull);
212+
} // Else implies addr is below the VA hole.
213+
214+
Address object = (new_object << kObjectPointerShift) & ~kMarkingBit;
215+
#else
186216
// We want to preserve the marking bit of the entry. Since that happens to
187217
// be the tag bit of the pointer, we need to explicitly clear it here.
188218
Address object =
189219
((new_object - kObjectPointerOffset) << kObjectPointerShift) &
190220
~kMarkingBit;
221+
#endif /* __illumos__ 64-bit */
191222
Address new_payload = object | marking_bit | parameter_count;
192223
encoded_word_.store(new_payload, std::memory_order_relaxed);
193224
entrypoint_.store(new_entrypoint, std::memory_order_relaxed);
@@ -214,7 +245,12 @@ void JSDispatchEntry::MakeFreelistEntry(uint32_t next_entry_index) {
214245
bool JSDispatchEntry::IsFreelistEntry() const {
215246
#ifdef V8_TARGET_ARCH_64_BIT
216247
auto entrypoint = entrypoint_.load(std::memory_order_relaxed);
248+
#ifdef __illumos__
249+
// See the illumos definition of kFreeEntryTag for why we have to do this.
250+
return (entrypoint & 0xffff000000000000) == kFreeEntryTag;
251+
#else
217252
return (entrypoint & kFreeEntryTag) == kFreeEntryTag;
253+
#endif /* __illumos__ */
218254
#else
219255
return next_free_entry_.load(std::memory_order_relaxed) != 0;
220256
#endif

deps/v8/src/sandbox/js-dispatch-table.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,33 @@ struct JSDispatchEntry {
8383
static constexpr uintptr_t kObjectPointerOffset = 0x0700000000000000;
8484
#elif defined(_AIX)
8585
static constexpr uintptr_t kObjectPointerOffset = 0x0a00000000000000;
86+
#elif defined(__illumos__) && defined(V8_TARGET_ARCH_64_BIT)
87+
// In illumos 64-bit apps, pointers are allocated from two sides of a
88+
// Virtual Address hole (VA hole). The VA hole spans 0x800000000000 to
89+
// 0xffff7fffffffffff. This means addresses either have 0xffff in the
90+
// high-16-bits, or 0 in it. If 0, we wanna be like all of the
91+
// other implementations or like an Oracle Solaris app linked with a VA47
92+
// mapfile (illumos may offer a VA47 someday, but not currently, and not
93+
// in older illumos distro versions).
94+
//
95+
// So we keep the 0xffff as our "kObjectPointerOffset", that way if we detect
96+
// the 48th bit set (0x800000000000) we know to use it, or else we use 0.
97+
// This will change, of course, if the VA hole ever shrinks, say to accomodate
98+
// amd64 5-level paging.
99+
static constexpr uintptr_t kObjectPointerOffset = 0xffff000000000000;
86100
#else
87101
static constexpr uintptr_t kObjectPointerOffset = 0;
88102
#endif
89103

90104
#if defined(V8_TARGET_ARCH_64_BIT)
91105
// Freelist entries contain the index of the next free entry in their lower 32
92106
// bits and are tagged with this tag.
107+
#ifdef __illumos__
108+
// illumos pointers may have 0xffff in them!!!
109+
static constexpr Address kFreeEntryTag = 0xfeed000000000000ull;
110+
#else
93111
static constexpr Address kFreeEntryTag = 0xffff000000000000ull;
112+
#endif /* __illumos__ */
94113
#ifdef V8_TARGET_BIG_ENDIAN
95114
// 2-byte parameter count is on the least significant side of encoded_word_.
96115
static constexpr int kBigEndianParamCountOffset =

0 commit comments

Comments
 (0)