Upstream Cobalt changes in base/ and utils/

- Updated implementation of platform-starboard
- Introducing stack_trace_starboard.cc
- Adding Starboard implementation for sys-info, random and memory
- Disabling some code in ostream.

Bug: v8:10927
Change-Id: I4548a413449fc8e43c5d4ae485b3644c60c07830
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2952864
Commit-Queue: John Xu <johnx@google.com>
Auto-Submit: John Xu <johnx@google.com>
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75495}
This commit is contained in:
John Xu 2021-07-01 02:53:34 +00:00 committed by V8 LUCI CQ
parent ae1eee10fa
commit 9c904a8f19
5 changed files with 54 additions and 41 deletions

View File

@ -4,7 +4,7 @@
// Platform-specific code for Starboard goes here. Starboard is the platform
// abstraction layer for Cobalt, an HTML5 container used mainly by YouTube
// apps in the livingroom.
// apps in the living room.
#include "src/base/lazy-instance.h"
#include "src/base/macros.h"
@ -12,6 +12,7 @@
#include "src/base/platform/time.h"
#include "src/base/timezone-cache.h"
#include "src/base/utils/random-number-generator.h"
#include "starboard/client_porting/eztime/eztime.h"
#include "starboard/common/condition_variable.h"
#include "starboard/common/log.h"
#include "starboard/common/string.h"
@ -71,6 +72,8 @@ static LazyInstance<RandomNumberGenerator>::type
static LazyMutex rng_mutex = LAZY_MUTEX_INITIALIZER;
bool g_hard_abort = false;
// We only use this stack size to get the topmost stack frame.
const int kStackSize = 1;
} // namespace
@ -149,37 +152,6 @@ void* Allocate(void* address, size_t size, OS::MemoryPermission access) {
return result;
}
// The following code was taken from old v8 to deal with rounding up pointers.
namespace {
// Compute the 0-relative offset of some absolute value x of type T.
// This allows conversion of Addresses and integral types into
// 0-relative int offsets.
template <typename T>
constexpr inline intptr_t OffsetFrom(T x) {
return x - static_cast<T>(0);
}
// Compute the absolute value of type T for some 0-relative offset x.
// This allows conversion of 0-relative int offsets into Addresses and
// integral types.
template <typename T>
constexpr inline T AddressFrom(intptr_t x) {
return static_cast<T>(static_cast<T>(0) + x);
}
template <typename T>
inline T RoundDown(T x, intptr_t m) {
// m must be a power of two.
DCHECK(m != 0 && ((m & (m - 1)) == 0));
return AddressFrom<T>(OffsetFrom(x) & -m);
}
template <typename T>
inline T RoundUpOld(T x, intptr_t m) {
return RoundDown<T>(static_cast<T>(x + m - 1), m);
}
} // namespace
// static
void* OS::Allocate(void* address, size_t size, size_t alignment,
MemoryPermission access) {
@ -195,7 +167,8 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
// Unmap memory allocated before the aligned base address.
uint8_t* base = static_cast<uint8_t*>(result);
uint8_t* aligned_base = RoundUpOld(base, alignment);
uint8_t* aligned_base = reinterpret_cast<uint8_t*>(
RoundUp(reinterpret_cast<uintptr_t>(base), alignment));
if (aligned_base != base) {
DCHECK_LT(base, aligned_base);
size_t prefix_size = static_cast<size_t>(aligned_base - base);
@ -430,10 +403,11 @@ void Thread::set_name(const char* name) {
name_[sizeof(name_) - 1] = '\0';
}
void Thread::Start() {
bool Thread::Start() {
data_->thread_ =
SbThreadCreate(stack_size_, kSbThreadNoPriority, kSbThreadNoAffinity,
true, name_, ThreadEntry, this);
return SbThreadIsValid(data_->thread_);
}
void Thread::Join() { SbThreadJoin(data_->thread_, nullptr); }
@ -457,7 +431,6 @@ void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
class StarboardTimezoneCache : public TimezoneCache {
public:
double DaylightSavingsOffset(double time_ms) override { return 0.0; }
void Clear(TimeZoneDetection time_zone_detection) override {}
~StarboardTimezoneCache() override {}
@ -471,7 +444,18 @@ class StarboardDefaultTimezoneCache : public StarboardTimezoneCache {
return SbTimeZoneGetName();
}
double LocalTimeOffset(double time_ms, bool is_utc) override {
return SbTimeZoneGetCurrent() * 60000.0;
// SbTimeZOneGetCurrent returns an offset west of Greenwich, which has the
// opposite sign V8 expects.
// The starboard function returns offset in minutes. We convert to return
// value in milliseconds.
return SbTimeZoneGetCurrent() * 60.0 * msPerSecond * (-1);
}
double DaylightSavingsOffset(double time_ms) override {
EzTimeValue value = EzTimeValueFromSbTime(SbTimeGetNow());
EzTimeExploded ez_exploded;
bool result =
EzTimeValueExplode(&value, kEzTimeZoneLocal, &ez_exploded, NULL);
return ez_exploded.tm_isdst > 0 ? 3600 * msPerSecond : 0;
}
~StarboardDefaultTimezoneCache() override {}
@ -495,5 +479,16 @@ bool OS::DiscardSystemPages(void* address, size_t size) {
return true;
}
// static
Stack::StackSlot Stack::GetCurrentStackPosition() {
void* addresses[kStackSize];
const size_t count = SbSystemGetStack(addresses, kStackSize);
if (count > 0) {
return addresses[0];
} else {
return nullptr;
}
}
} // namespace base
} // namespace v8

View File

@ -26,6 +26,10 @@
#include "src/base/win32-headers.h"
#endif
#if V8_OS_STARBOARD
#include "starboard/system.h"
#endif
namespace v8 {
namespace base {
@ -49,6 +53,8 @@ int SysInfo::NumberOfProcessors() {
SYSTEM_INFO system_info = {};
::GetNativeSystemInfo(&system_info);
return static_cast<int>(system_info.dwNumberOfProcessors);
#elif V8_OS_STARBOARD
return SbSystemGetNumberOfProcessors();
#endif
}
@ -97,6 +103,8 @@ int64_t SysInfo::AmountOfPhysicalMemory() {
return 0;
}
return static_cast<int64_t>(pages) * page_size;
#elif V8_OS_STARBOARD
return SbSystemGetTotalCPUMemory();
#endif
}
@ -112,6 +120,8 @@ int64_t SysInfo::AmountOfVirtualMemory() {
return 0;
}
return (rlim.rlim_cur == RLIM_INFINITY) ? 0 : rlim.rlim_cur;
#elif V8_OS_STARBOARD
return 0;
#endif
}

View File

@ -6,6 +6,9 @@
#include <stdio.h>
#include <stdlib.h>
#if defined(V8_OS_STARBOARD)
#include "starboard/system.h"
#endif // V8_OS_STARBOARD
#include <algorithm>
#include <new>
@ -59,6 +62,8 @@ RandomNumberGenerator::RandomNumberGenerator() {
int64_t seed;
arc4random_buf(&seed, sizeof(seed));
SetSeed(seed);
#elif V8_OS_STARBOARD
SetSeed(SbSystemGetRandomUInt64());
#else
// Gather entropy from /dev/urandom if available.
FILE* fp = base::Fopen("/dev/urandom", "rb");

View File

@ -1,4 +1,4 @@
// Copyright 2012 the V8 project authors. All rights reserved.
// Copyright 2012 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -12,6 +12,7 @@
#include "src/base/logging.h"
#include "src/base/page-allocator.h"
#include "src/base/platform/platform.h"
#include "src/base/platform/wrappers.h"
#include "src/base/sanitizer/lsan-page-allocator.h"
#include "src/base/vector.h"
#include "src/flags/flags.h"
@ -20,8 +21,6 @@
#if V8_LIBC_BIONIC
#include <malloc.h>
#include "src/base/platform/wrappers.h"
#endif
namespace v8 {
@ -37,6 +36,8 @@ void* AlignedAllocInternal(size_t size, size_t alignment) {
// posix_memalign is not exposed in some Android versions, so we fall back to
// memalign. See http://code.google.com/p/android/issues/detail?id=35391.
ptr = memalign(alignment, size);
#elif V8_OS_STARBOARD
ptr = SbMemoryAllocateAligned(alignment, size);
#else
if (posix_memalign(&ptr, alignment, size)) ptr = nullptr;
#endif
@ -147,6 +148,8 @@ void AlignedFree(void* ptr) {
#elif V8_LIBC_BIONIC
// Using free is not correct in general, but for V8_LIBC_BIONIC it is.
base::Free(ptr);
#elif V8_OS_STARBOARD
SbMemoryFreeAligned(ptr);
#else
base::Free(ptr);
#endif

View File

@ -25,7 +25,7 @@ V8_EXPORT_PRIVATE void MemMove(void* dest, const void* src, size_t size) {
// on all architectures we currently support.
(*memmove_function)(dest, src, size);
}
#elif V8_OS_POSIX && V8_HOST_ARCH_ARM
#elif(V8_OS_POSIX || V8_OS_STARBOARD) && V8_HOST_ARCH_ARM
V8_EXPORT_PRIVATE MemCopyUint8Function memcopy_uint8_function =
&MemCopyUint8Wrapper;
#elif V8_OS_POSIX && V8_HOST_ARCH_MIPS
@ -40,7 +40,7 @@ void init_memcopy_functions() {
memmove_function = reinterpret_cast<MemMoveFunction>(
d.InstructionStartOfBuiltin(Builtin::kMemMove));
}
#elif V8_OS_POSIX && V8_HOST_ARCH_ARM
#elif(V8_OS_POSIX || V8_OS_STARBOARD) && V8_HOST_ARCH_ARM
if (Isolate::CurrentEmbeddedBlobIsBinaryEmbedded()) {
EmbeddedData d = EmbeddedData::FromBlob();
memcopy_uint8_function = reinterpret_cast<MemCopyUint8Function>(