/*
 * The contents of this file are subject to the Netscape Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/NPL/

 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.

 * The Original Code is Rhino code, released
 * May 6, 1999.

 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
 * Rights Reserved.

 * Contributor(s): 

 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Public License (the "GPL"), in which case the
 * provisions of the GPL are applicable instead of those above.
 * If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use your
 * version of this file under the NPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this
 * file under either the NPL or the GPL.
 */
/*
File:      js-mem.h (was: ewb-mem.h)
Contents:  Local Memory Access Libraries definition file header.
08.May.00: Created by S.Takaoka
           Prime)CP&S STD Fuji Xerox Co.,Ltd.

*/

#ifndef _JS_MEM_H_
#define _JS_MEM_H_

#include <stdlib.h>

#ifdef  __cplusplus
extern "C" {
#endif

#if 0
#define EWB_MEM_DEBUG
#endif
#if 1 /* Divide MemPart SMALL and BIG */
 extern int   EwbMemInit( size_t size, size_t small_size,
                          size_t bytecode_size, size_t js_size, size_t jszone_size);
#else
 extern int   EwbMemInit( size_t size, size_t bytecode_size, size_t img_size, size_t js_size, size_t jszone_size);
#endif
extern  void  EwbMemPartSuspendMode( void );
extern  void  EwbMemShow( void );
extern  void  EwbJSMemShow( void );
extern  void  EwbMem_sysMemMaxReset( void );

extern  void *EwbMalloc_no( size_t size );
extern  void  EwbMFree( void *ptr );
extern  void *EwbMRealloc_no( void *ptr, size_t size );
extern  void *EwbMCalloc_no( size_t n, size_t size );
extern  void  EwbMCFree(  void *ptr );
extern  void *EwbMAlignedAlloc_no( size_t, size_t );

#if 0 /* Divide MemPart SMALL and BIG */
  extern  void *EwbImgMalloc( size_t size ); //20040629 ichino
  extern  void  EwbImgMFree( void  *ptr );
#endif

extern void *ByteCodeMalloc  ( size_t size );
extern void  ByteCodeMFree( void *ptr );
extern void *ByteCodeMAlignedAlloc( size_t size, size_t align );

extern void *JsMalloc  ( size_t size );
extern void  JsMFree( void *ptr );
extern void *JsMAlignedAlloc( size_t size, size_t align );

extern void *JsZoneMalloc  ( size_t size );
extern void  JsZoneMFree( void *ptr );
extern void *JsZoneMAlignedAlloc( size_t size, size_t align );
extern int   JsZoneGetMax();
extern void  JsZoneResetMax();

extern void* EwbMemSizeCheck(int size);
extern void *EwbMemSizeCheckShow();

#if defined(VX)
extern void  EwbJSMemSysLog( void );
extern void  EwbJSMemShow( void );
#endif

#if defined(VX) && defined(EWB_MEM_DEBUG)
 extern void  EwbMemClear( void );
 extern void* EwbMalloc_ent( size_t, char*, int );
 extern void* EwbMRealloc_ent( void*, size_t, char*, int );
 extern void* EwbMCalloc_ent( size_t, size_t, char*, int );
 extern void* EwbMAlignedAlloc_ent( size_t, size_t, char*, int );
#endif

#if defined(VX) && defined(EWB_MEM_DEBUG)
 #define EwbMalloc(s)           EwbMalloc_ent((s),__FILE__,__LINE__)
 #define EwbMRealloc(p,s)       EwbMRealloc_ent((p),(s),__FILE__,__LINE__)
 #define EwbMCalloc(s,c)        EwbMCalloc_ent((s),(c),__FILE__,__LINE__)
 #define EwbMAlignedAlloc(s,a)  EwbMAlignedAlloc_ent((s),(a),__FILE__,__LINE__)
#else
 #define EwbMalloc(s)           EwbMalloc_no(s)
 #define EwbMRealloc(p,s)       EwbMRealloc_no(p,s)
 #define EwbMCalloc(s,c)        EwbMCalloc_no(s,c)
 #define EwbMAlignedAlloc(s,a)  EwbMAlignedAlloc_no((s),(a))
#endif

#define EWB_OK  0
#define EWB_NG  -1

extern  void    ewb_memCheck(const char* pszFile, unsigned line);
#define MEM_CHECK()   ewb_memCheck(__FILE__, __LINE__)

#ifdef  __cplusplus
}
#endif

#endif  /* _JS_MEM_H_ */
