Title: [294905] trunk/Source/_javascript_Core/runtime/JSCellInlines.h
Revision
294905
Author
[email protected]
Date
2022-05-26 15:51:13 -0700 (Thu, 26 May 2022)

Log Message

Re-factoring clean up in allocateCell and tryAllocateCell.
https://bugs.webkit.org/show_bug.cgi?id=240973

Reviewed by Saam Barati.

The AllocationFailureMode should be a template parameter to tryAllocateCellHelper because it's
constant.  Also, tryAllocateCellHelper should take a VM& instead of taking a Heap& and then
converting it back to a VM&.

* Source/_javascript_Core/runtime/JSCellInlines.h:
(JSC::tryAllocateCellHelper):
(JSC::allocateCell):
(JSC::tryAllocateCell):

Canonical link: https://commits.webkit.org/251028@main

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/runtime/JSCellInlines.h (294904 => 294905)


--- trunk/Source/_javascript_Core/runtime/JSCellInlines.h	2022-05-26 22:39:00 UTC (rev 294904)
+++ trunk/Source/_javascript_Core/runtime/JSCellInlines.h	2022-05-26 22:51:13 UTC (rev 294905)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2021 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
@@ -167,15 +167,16 @@
     return { };
 }
 
-template<typename T>
-ALWAYS_INLINE void* tryAllocateCellHelper(Heap& heap, size_t size, GCDeferralContext* deferralContext, AllocationFailureMode failureMode)
+template<typename T, AllocationFailureMode failureMode>
+ALWAYS_INLINE void* tryAllocateCellHelper(VM& vm, size_t size, GCDeferralContext* deferralContext)
 {
-    VM& vm = heap.vm();
-    ASSERT(deferralContext || heap.isDeferred() || !DisallowGC::isInEffectOnCurrentThread());
+    ASSERT(deferralContext || vm.heap.isDeferred() || !DisallowGC::isInEffectOnCurrentThread());
     ASSERT(size >= sizeof(T));
     JSCell* result = static_cast<JSCell*>(subspaceFor<T>(vm)->allocate(vm, size, deferralContext, failureMode));
-    if (failureMode == AllocationFailureMode::ReturnNull && !result)
-        return nullptr;
+    if constexpr (failureMode == AllocationFailureMode::ReturnNull) {
+        if (!result)
+            return nullptr;
+    }
 #if ENABLE(GC_VALIDATION)
     ASSERT(!vm.isInitializingObject());
     vm.setInitializingObjectClass(T::info());
@@ -187,25 +188,25 @@
 template<typename T>
 void* allocateCell(VM& vm, size_t size)
 {
-    return tryAllocateCellHelper<T>(vm.heap, size, nullptr, AllocationFailureMode::Assert);
+    return tryAllocateCellHelper<T, AllocationFailureMode::Assert>(vm, size, nullptr);
 }
 
 template<typename T>
 void* tryAllocateCell(VM& vm, size_t size)
 {
-    return tryAllocateCellHelper<T>(vm.heap, size, nullptr, AllocationFailureMode::ReturnNull);
+    return tryAllocateCellHelper<T, AllocationFailureMode::ReturnNull>(vm, size, nullptr);
 }
 
 template<typename T>
 void* allocateCell(VM& vm, GCDeferralContext* deferralContext, size_t size)
 {
-    return tryAllocateCellHelper<T>(vm.heap, size, deferralContext, AllocationFailureMode::Assert);
+    return tryAllocateCellHelper<T, AllocationFailureMode::Assert>(vm, size, deferralContext);
 }
 
 template<typename T>
 void* tryAllocateCell(VM& vm, GCDeferralContext* deferralContext, size_t size)
 {
-    return tryAllocateCellHelper<T>(vm.heap, size, deferralContext, AllocationFailureMode::ReturnNull);
+    return tryAllocateCellHelper<T, AllocationFailureMode::ReturnNull>(vm, size, deferralContext);
 }
 
 inline bool JSCell::isObject() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to