/*
 * Licensed Materials - Property of IBM
 * IBM Developer Kit, Java(TM) Tech Edition
 * (c) Copyright IBM Corp. 1996, 1999. All rights reserved.
 *
 * US Government Users Restricted Rights - Use,
 * duplication or disclosure restricted by GSA
 * ADP Schedule Contract with IBM Corp.
 */
/*
 * @(#)alloc_cache.h	1.4 98/02/04
 *
 * Copyright 1993-1997 Sun Microsystems, Inc. 901 San Antonio Road,
 * Palo Alto, California, 94303, U.S.A.  All Rights Reserved.
 *
 */

/*
 * Per-thread allocation cache
 */

#ifndef	_ALLOC_CACHE_H_
#define	_ALLOC_CACHE_H_

#if defined(IBM_INTEL)							/*ibm.8904*/
#define COMPACTION_AVOIDANCE
#endif									/*ibm.8904*/

#ifdef JMS_TRL

/* Default cache (refill) size */
#define	ALLOC_CACHE_SIZE	1536
#ifdef COMPACTION_AVOIDANCE						/*ibm.8904*/
/* Desired cache (refill) size */
#define ALLOC_CACHE_TARGET      (ALLOC_CACHE_SIZE*4)
/* Smallest acceptable average size */
#define ALLOC_CACHE_MIN         1000
#endif /* COMPACTION_AVOIDANCE */					/*ibm.8904*/
/* Default maximum local allocation size, must be less than cache size */
#define	ALLOC_LOCAL_SIZE	(ALLOC_CACHE_SIZE/4)

/*
 * Per-thread structure
 */
struct alloc_cache {
    volatile char	cache_busy;
    char	cache_pad[3];
    long	cache_size;
    JHandle    *cache_block;
    long        safe_low;
    long        safe_high;
};

/* Cache (refill) size */
extern long allocCacheSize;

/* Allocations smaller than this are attempted from local cache.  Use
   0 to turn off local allocation.  Must be less than cache size. */
extern long allocLocalSize;

/* Callback when thread exits */
extern void allocCacheCleanup(struct alloc_cache *);

#else /* JMS_TRL */ /* SUN */

/* Default cache (refill) size */
#define	ALLOC_CACHE_SIZE	1024
/* Default maximum local allocation size, must be less than cache size */
#define	ALLOC_LOCAL_SIZE	(ALLOC_CACHE_SIZE/4)
/* Default handle cache refill count */
#define	ALLOC_HANDLE_COUNT	(ALLOC_CACHE_SIZE/8/3)

/*
 * Per-thread structure
 */
struct alloc_cache {
    volatile char	cache_busy;
    char	cache_pad[3];
    long	cache_size;
    void	*cache_tail;
    void	*cache_handles;
};

/* Cache (refill) size */
extern long allocCacheSize;

/* Allocations smaller than this are attempted from local cache.  Use
   0 to turn off local allocation.  Must be less than cache size. */
extern long allocLocalSize;

/* Cache handle refill count */
extern long allocHandleCount;

/* Callback when thread exits */
extern void allocCacheCleanup(struct alloc_cache *);
#endif  /* JMS_TRL */

#endif /* _ALLOC_CACHE_H */
