Skip to content
Permalink
Browse files
Enhance RawPointer to take function pointers as well.
https://bugs.webkit.org/show_bug.cgi?id=241773

Reviewed by Yusuke Suzuki.

Also add PageBlock::end and PageReservation::end methods to make code a little
more readable (motivated by a RawPointer use).

* Source/JavaScriptCore/API/JSMarkingConstraintPrivate.cpp:
(JSContextGroupAddMarkingConstraint):
* Source/JavaScriptCore/heap/HeapFinalizerCallback.cpp:
(JSC::HeapFinalizerCallback::dump const):
* Source/JavaScriptCore/jit/ExecutableAllocator.cpp:
(JSC::initializeJITPageReservation):
* Source/WTF/wtf/PageBlock.h:
(WTF::PageBlock::end const):
* Source/WTF/wtf/PageReservation.h:
* Source/WTF/wtf/RawPointer.h:
(WTF::RawPointer::RawPointer):

Canonical link: https://commits.webkit.org/251685@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295680 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Mark Lam committed Jun 21, 2022
1 parent 4db94c2 commit dbdd3c45567aa7527c5b755aa332da53168adad1
Showing 6 changed files with 17 additions and 9 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2021 Apple Inc. All rights reserved.
* Copyright (C) 2017-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -71,8 +71,8 @@ void JSContextGroupAddMarkingConstraint(JSContextGroupRef group, JSMarkingConstr
ConstraintVolatility volatility = ConstraintVolatility::GreyedByMarking;

auto constraint = makeUnique<SimpleMarkingConstraint>(
toCString("Amc", constraintIndex, "(", RawPointer(bitwise_cast<void*>(constraintCallback)), ")"),
toCString("API Marking Constraint #", constraintIndex, " (", RawPointer(bitwise_cast<void*>(constraintCallback)), ", ", RawPointer(userData), ")"),
toCString("Amc", constraintIndex, "(", RawPointer(constraintCallback), ")"),
toCString("API Marking Constraint #", constraintIndex, " (", RawPointer(constraintCallback), ", ", RawPointer(userData), ")"),
MAKE_MARKING_CONSTRAINT_EXECUTOR_PAIR(([constraintCallback, userData] (AbstractSlotVisitor& visitor) {
Marker marker;
marker.IsMarked = isMarked;
@@ -33,7 +33,7 @@ namespace JSC {

void HeapFinalizerCallback::dump(PrintStream& out) const
{
out.print(RawPointer(bitwise_cast<void*>(m_finalizer)), ":", RawPointer(m_userData));
out.print(RawPointer(m_finalizer), ":", RawPointer(m_userData));
}

void HeapFinalizerCallback::run(VM& vm) const
@@ -386,7 +386,7 @@ static ALWAYS_INLINE JITReservation initializeJITPageReservation()
reservation.pageReservation = tryCreatePageReservation(reservation.size);

if (Options::verboseExecutablePoolAllocation())
dataLog(getpid(), ": Got executable pool reservation at ", RawPointer(reservation.pageReservation.base()), "...", RawPointer(bitwise_cast<char*>(reservation.pageReservation.base()) + reservation.pageReservation.size()), ", while I'm at ", RawPointer(bitwise_cast<void*>(initializeJITPageReservation)), "\n");
dataLog(getpid(), ": Got executable pool reservation at ", RawPointer(reservation.pageReservation.base()), "...", RawPointer(reservation.pageReservation.end()), ", while I'm at ", RawPointer(bitwise_cast<void*>(initializeJITPageReservation)), "\n");

if (reservation.pageReservation) {
ASSERT(reservation.pageReservation.size() == reservation.size);
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
* Copyright (C) 2010-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -69,6 +69,7 @@ class PageBlock {
PageBlock(void*, size_t, bool hasGuardPages);

void* base() const { return m_base; }
void* end() const { return reinterpret_cast<uint8_t*>(m_base) + size(); }

This comment has been minimized.

Copy link
@darinadler

darinadler Jun 21, 2022

Member

This should be static_cast instead of reinterpret_cast. There is a special case for static_cast from void* just for cases like this.

size_t size() const { return m_size; }

operator bool() const { return !!m_realBase; }
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
* Copyright (C) 2010-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -58,6 +58,7 @@ class PageReservation : private PageBlock {
PageReservation() = default;

using PageBlock::base;
using PageBlock::end;
using PageBlock::size;
using PageBlock::operator bool;

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
* Copyright (C) 2012-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -43,7 +43,13 @@ class RawPointer {
: m_value(value)
{
}


template<typename T, typename = std::enable_if_t<std::is_function_v<T>, T>>
explicit RawPointer(T* value)
: m_value(reinterpret_cast<const void*>(value))
{
}

const void* value() const { return m_value; }

private:

0 comments on commit dbdd3c4

Please sign in to comment.