16e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 26e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Copyright (C) 2010 The Android Open Source Project 36e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * 46e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Licensed under the Apache License, Version 2.0 (the "License"); 56e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * you may not use this file except in compliance with the License. 66e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * You may obtain a copy of the License at 76e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * 86e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * http://www.apache.org/licenses/LICENSE-2.0 96e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * 106e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Unless required by applicable law or agreed to in writing, software 116e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * distributed under the License is distributed on an "AS IS" BASIS, 126e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * See the License for the specific language governing permissions and 146e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * limitations under the License. 156e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 166e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 176e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 186e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Maintain a card table from the the write barrier. All writes of 196e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * non-NULL values to heap addresses should go through an entry in 206e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * WriteBarrier, and from there to here. 216e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 226e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 23375fb116bcb817b37509ab579dbd55cdbb765cbfCarl Shapiro#ifndef DALVIK_ALLOC_CARDTABLE_H_ 24375fb116bcb817b37509ab579dbd55cdbb765cbfCarl Shapiro#define DALVIK_ALLOC_CARDTABLE_H_ 256e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 266e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes#define GC_CARD_SHIFT 7 276e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes#define GC_CARD_SIZE (1 << GC_CARD_SHIFT) 286e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes#define GC_CARD_CLEAN 0 296e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes#define GC_CARD_DIRTY 0x70 306e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 316e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 326e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Initializes the card table; must be called before any other 336e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * dvmCardTable*() functions. 346e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 35af6cf54652d1b27885b99e216bee29b955052630Andy McFaddenbool dvmCardTableStartup(size_t heapMaximumSize, size_t growthLimit); 366e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 376e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 386e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Tears down the entire CardTable structure. 396e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 406e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayesvoid dvmCardTableShutdown(void); 416e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 426e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 43106c5fd9745a47d663e28217f3dd5ac48f606f81Carl Shapiro * Resets all of the bytes in the card table to clean. 44106c5fd9745a47d663e28217f3dd5ac48f606f81Carl Shapiro */ 45106c5fd9745a47d663e28217f3dd5ac48f606f81Carl Shapirovoid dvmClearCardTable(void); 46106c5fd9745a47d663e28217f3dd5ac48f606f81Carl Shapiro 47106c5fd9745a47d663e28217f3dd5ac48f606f81Carl Shapiro/* 488f921a79b7e4f93905d8bb5c1b844d0acc5a8a2dBarry Hayes * Returns the address of the relevent byte in the card table, given 496e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * an address on the heap. 506e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 516e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayesu1 *dvmCardFromAddr(const void *addr); 526e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 538f921a79b7e4f93905d8bb5c1b844d0acc5a8a2dBarry Hayes/* 548f921a79b7e4f93905d8bb5c1b844d0acc5a8a2dBarry Hayes * Returns the first address in the heap which maps to this card. 558f921a79b7e4f93905d8bb5c1b844d0acc5a8a2dBarry Hayes */ 566e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayesvoid *dvmAddrFromCard(const u1 *card); 576e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 586e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 597a136d89e7a335f46fd85e4f28d1c5d8cb3bc9c7Carl Shapiro * Returns true if addr points to a valid card. 607a136d89e7a335f46fd85e4f28d1c5d8cb3bc9c7Carl Shapiro */ 61f44af1c40f4a81aed17765671b100edeeec28dabCarl Shapirobool dvmIsValidCard(const u1 *card); 627a136d89e7a335f46fd85e4f28d1c5d8cb3bc9c7Carl Shapiro 637a136d89e7a335f46fd85e4f28d1c5d8cb3bc9c7Carl Shapiro/* 646e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes * Set the card associated with the given address to GC_CARD_DIRTY. 656e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 666e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayesvoid dvmMarkCard(const void *addr); 676e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 686e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes/* 695ba39376c5b7a5878f234a689a51c74783583b4bCarl Shapiro * Verifies that all gray objects are on a dirty card. 706e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes */ 719d2902a18fbd12481cdba764566d92b445593728Barry Hayesvoid dvmVerifyCardTable(void); 726e5cf6021b2f3e00e18ab402f23ab93b27c6061bBarry Hayes 73375fb116bcb817b37509ab579dbd55cdbb765cbfCarl Shapiro#endif // DALVIK_ALLOC_CARDTABLE_H_ 74