2 * Copyright (c) 2004-2007 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 #include <sys/types.h>
31 #include <AvailabilityMacros.h>
33 /* Collection utilities */
37 OBJC_RATIO_COLLECTION
= (0 << 0), // run "ratio" generational collections, then a full
38 OBJC_GENERATIONAL_COLLECTION
= (1 << 0), // run fast incremental collection
39 OBJC_FULL_COLLECTION
= (2 << 0), // run full collection.
40 OBJC_EXHAUSTIVE_COLLECTION
= (3 << 0), // run full collections until memory available stops improving
42 OBJC_COLLECT_IF_NEEDED
= (1 << 3), // run collection only if needed (allocation threshold exceeded)
43 OBJC_WAIT_UNTIL_DONE
= (1 << 4), // wait (when possible) for collection to end before returning (when collector is running on dedicated thread)
46 OBJC_EXPORT
void objc_collect(unsigned long options
);
47 OBJC_EXPORT BOOL
objc_collectingEnabled(void);
50 /* GC configuration */
52 /* Tells collector to wait until specified bytes have been allocated before trying to collect again. */
53 OBJC_EXPORT
void objc_setCollectionThreshold(size_t threshold
);
55 /* Tells collector to run a full collection for every ratio generational collections. */
56 OBJC_EXPORT
void objc_setCollectionRatio(size_t ratio
);
58 /* Tells collector to start collecting on dedicated thread */
59 OBJC_EXPORT
void objc_startCollectorThread(void);
62 // atomic update of a global variable
63 OBJC_EXPORT BOOL
objc_atomicCompareAndSwapGlobal(id predicate
, id replacement
, volatile id
*objectLocation
);
64 OBJC_EXPORT BOOL
objc_atomicCompareAndSwapGlobalBarrier(id predicate
, id replacement
, volatile id
*objectLocation
);
65 // atomic update of an instance variable
66 OBJC_EXPORT BOOL
objc_atomicCompareAndSwapInstanceVariable(id predicate
, id replacement
, volatile id
*objectLocation
);
67 OBJC_EXPORT BOOL
objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate
, id replacement
, volatile id
*objectLocation
);
69 /* Write barriers. Used by the compiler. */
70 OBJC_EXPORT id
objc_assign_strongCast(id val
, id
*dest
);
71 OBJC_EXPORT id
objc_assign_global(id val
, id
*dest
);
72 OBJC_EXPORT id
objc_assign_ivar(id value
, id dest
, ptrdiff_t offset
);
73 OBJC_EXPORT
void *objc_memmove_collectable(void *dst
, const void *src
, size_t size
);
75 OBJC_EXPORT id
objc_read_weak(id
*location
);
76 OBJC_EXPORT id
objc_assign_weak(id value
, id
*location
);
80 // SPI. The following routines are available as debugging and transitional aides.
83 /* Tells runtime to issue finalize calls on the main thread only. */
84 OBJC_EXPORT
void objc_finalizeOnMainThread(Class cls
)
85 AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER_BUT_DEPRECATED
;
88 /* ask if object is scheduled for finalization. Safe only when called from within a finalizer. */
89 OBJC_EXPORT BOOL
objc_is_finalized(void *ptr
);
92 OBJC_CLEAR_RESIDENT_STACK
= (1 << 0)
95 /* Stack management */
96 OBJC_EXPORT
void objc_clear_stack(unsigned long options
);
99 // Obsolete. Present only until all uses can be migrated to newer API.
102 OBJC_EXPORT BOOL
objc_collecting_enabled(void);
103 OBJC_EXPORT
void objc_set_collection_threshold(size_t threshold
);
104 OBJC_EXPORT
void objc_set_collection_ratio(size_t ratio
);
105 OBJC_EXPORT
void objc_start_collector_thread(void);
107 /* Memory management */
108 OBJC_EXPORT id
objc_allocate_object(Class cls
, int extra
);
111 OBJC_GENERATIONAL
= (1 << 0)
114 OBJC_EXPORT
void objc_collect_if_needed(unsigned long options
);