Skip to content

Commit 8738ab8

Browse files
jakobkummerowCommit Bot
authored andcommitted
[ptr-compr] Fix decompression functions in v8-internal.h
In the final version of our pointer compression scheme, decompression uses zero-extension of the compressed value. The API copy of that code erroneously still used a sign-extending decompression from an earlier iteration of the scheme. Bug: v8:9706, v8:10198 Change-Id: I17c3a52d26ce26bc0623627d725f686c379fbd6e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2051954 Commit-Queue: Jakob Kummerow <[email protected]> Reviewed-by: Ulan Degenbaev <[email protected]> Reviewed-by: Igor Sheludko <[email protected]> Cr-Commit-Position: refs/heads/master@{#66256}
1 parent 6516b1c commit 8738ab8

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

include/v8-internal.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ class Internals {
308308
V8_INLINE static internal::Address ReadTaggedPointerField(
309309
internal::Address heap_object_ptr, int offset) {
310310
#ifdef V8_COMPRESS_POINTERS
311-
int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
311+
uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
312312
internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
313-
return root + static_cast<internal::Address>(static_cast<intptr_t>(value));
313+
return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
314314
#else
315315
return ReadRawField<internal::Address>(heap_object_ptr, offset);
316316
#endif
@@ -319,8 +319,8 @@ class Internals {
319319
V8_INLINE static internal::Address ReadTaggedSignedField(
320320
internal::Address heap_object_ptr, int offset) {
321321
#ifdef V8_COMPRESS_POINTERS
322-
int32_t value = ReadRawField<int32_t>(heap_object_ptr, offset);
323-
return static_cast<internal::Address>(static_cast<intptr_t>(value));
322+
uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
323+
return static_cast<internal::Address>(static_cast<uintptr_t>(value));
324324
#else
325325
return ReadRawField<internal::Address>(heap_object_ptr, offset);
326326
#endif
@@ -337,13 +337,9 @@ class Internals {
337337
}
338338

339339
V8_INLINE static internal::Address DecompressTaggedAnyField(
340-
internal::Address heap_object_ptr, int32_t value) {
341-
internal::Address root_mask = static_cast<internal::Address>(
342-
-static_cast<intptr_t>(value & kSmiTagMask));
343-
internal::Address root_or_zero =
344-
root_mask & GetRootFromOnHeapAddress(heap_object_ptr);
345-
return root_or_zero +
346-
static_cast<internal::Address>(static_cast<intptr_t>(value));
340+
internal::Address heap_object_ptr, uint32_t value) {
341+
internal::Address root = GetRootFromOnHeapAddress(heap_object_ptr);
342+
return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
347343
}
348344
#endif // V8_COMPRESS_POINTERS
349345
};

include/v8.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11239,7 +11239,7 @@ Local<Value> Object::GetInternalField(int index) {
1123911239
#ifdef V8_COMPRESS_POINTERS
1124011240
// We read the full pointer value and then decompress it in order to avoid
1124111241
// dealing with potential endiannes issues.
11242-
value = I::DecompressTaggedAnyField(obj, static_cast<int32_t>(value));
11242+
value = I::DecompressTaggedAnyField(obj, static_cast<uint32_t>(value));
1124311243
#endif
1124411244
internal::Isolate* isolate =
1124511245
internal::IsolateFromNeverReadOnlySpaceObject(obj);
@@ -11883,7 +11883,7 @@ Local<Value> Context::GetEmbedderData(int index) {
1188311883
// We read the full pointer value and then decompress it in order to avoid
1188411884
// dealing with potential endiannes issues.
1188511885
value =
11886-
I::DecompressTaggedAnyField(embedder_data, static_cast<int32_t>(value));
11886+
I::DecompressTaggedAnyField(embedder_data, static_cast<uint32_t>(value));
1188711887
#endif
1188811888
internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(
1188911889
*reinterpret_cast<A*>(this));

0 commit comments

Comments
 (0)