📄 cache.h
字号:
/*0001*//*
/*0002./ * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
/*0003./ *
/*0004./ * This software is the confidential and proprietary information of Sun
/*0005./ * Microsystems, Inc. ("Confidential Information"). You shall not
/*0006./ * disclose such Confidential Information and shall use it only in
/*0007./ * accordance with the terms of the license agreement you entered into
/*0008./ * with Sun.
/*0009./ *
/*0010./ * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
/*0011./ * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
/*0012./ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/*0013./ * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
/*0014./ * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
/*0015./ * THIS SOFTWARE OR ITS DERIVATIVES.
/*0016./ *
/*0017./ */
/*0018*/
/*0019*//*=========================================================================
/*0020./ * SYSTEM: KVM
/*0021./ * SUBSYSTEM: Internal runtime structures
/*0022./ * FILE: cache.h
/*0023./ * OVERVIEW: Inline caching support.
/*0024./ * AUTHOR: Antero Taivalsaari, Sun Labs
/*0025./ *=======================================================================*/
/*0026*/
/*0027*//*=========================================================================
/*0028./ * COMMENTS:
/*0029./ * In order to reach reasonable execution performance without fancy
/*0030./ * compilation techniques, we are using a simple Deutsch-Schiffman
/*0031./ * Smalltalk-style inline caching for optimizing message sending
/*0032./ * and other bytecodes.
/*0033./ *
/*0034./ * If the optimization mode is enabled (ENABLEFASTBYTECODES), many
/*0035./ * bytecodes are patched at runtime with inline cache entries so
/*0036./ * that we can avoid costly constant pool and method table
/*0037./ * lookup in most situations. Since Java message sending
/*0038./ * bytecodes do not have enough space for truly inlined
/*0039./ * parameters, a special inline cache area is allocated
/*0040./ * separately and individual inline cache entries are
/*0041./ * referenced by indices from the code.
/*0042./ *
/*0043./ * Code before optimization:
/*0044./ * ... +----+--------+ ...
/*0045./ * | BC | PARAM | BC = "slow" bytecode (8 bits)
/*0046./ * ... +----+--------+ ... PARAM = parameter for BC (16 bits)
/*0047./ *
/*0048./ * Code after optimization:
/*0049./ * ... +----+--------+ ...
/*0050./ * | BF | ICIDX | BF = "fast" bytecode (8 bits)
/*0051./ * ... +----+--------+ ... ICIDX = inline cache index (16 bits)
/*0052./ *
/*0053./ * The optimization process is fully reversible and repeatable,
/*0054./ * i.e., we can de-optimize code at any point if necessary.
/*0055./ *=======================================================================*/
/*0056*/
/*0057*//*=========================================================================
/*0058./ * Include files
/*0059./ *=======================================================================*/
/*0060*/
/*0061*//*=========================================================================
/*0062./ * Global variables and definitions
/*0063./ *=======================================================================*/
/*0064*/
/*0065*//* The master inline cache in the system */
/*0066*//* In principle, each thread could have its own inline cache area, */
/*0067*//* but this would not improve performance substantially. */
/*0068*/extern ICACHE InlineCache;
/*0069*/
/*0070*//* Index of the next inline cache entry to be used */
/*0071*/extern int InlineCachePointer;
/*0072*/
/*0073*//*=========================================================================
/*0074./ * Inline cache structures
/*0075./ *=======================================================================*/
/*0076*/
/*0077*//*=========================================================================
/*0078./ * COMMENTS:
/*0079./ * ICACHE is a structure for storing individual inline cache entries.
/*0080./ * The whole inline cache is simply a contiguous array of ICACHE entries.
/*0081./ *
/*0082./ * Each inline cache entry contains a forward pointer to the actual method
/*0083./ * to be executed, a backpointer to the location of code referring to
/*0084./ * to inline cache entry, and the original contents of code (before
/*0085./ * inline patching) so that inline cached can be removed if necessary.
/*0086./ *
/*0087./ * There is a fixed number of inline cache entries in the system.
/*0088./ * Once the inline cache area is full, we start reusing the oldest
/*0089./ * entries starting from the beginning of the icache area.
/*0090./ * The code of the methods referring to the reused icache entries
/*0091./ * is replaced with the original (pre-inline cache) code. In other
/*0092./ * words, the whole inline caching process is completely reversable
/*0093./ * and repeatable.
/*0094./ *
/*0095./ * Note: in order to avoid garbage collection problems, we
/*0096./ * do not store any dynamic heap pointers in inline caches!
/*0097./ * This ensures that we can simply ignore the whole inline cache
/*0098./ * area during garbage collection.
/*0099./ *=======================================================================*/
/*0100*/
/*0101*//* ICACHE (allocated in inline cache area) */
/*0102*/struct icacheStruct {
/*0103*/ cell* contents; /* Cache contents (used differently in different entries) */
/*0104*/ BYTE* codeLoc; /* Backpointer to the code location using this icache */
/*0105*/ short origParam; /* Original bytecode parameter in (codeLoc+1) */
/*0106*/ BYTE origInst; /* Original bytecode instruction in codeLoc */
/*0107*/};
/*0108*/
/*0109*/#define SIZEOF_ICACHE StructSizeInCells(icacheStruct)
/*0110*/
/*0111*/#if ENABLEFASTBYTECODES
/*0112*/
/*0113*/ /*=========================================================================
/*0114./ * Constructor/destructors for (re)initializing inline caching
/*0115./ *=======================================================================*/
/*0116*/
/*0117*/ void InitializeInlineCaching();
/*0118*/ void FinalizeInlineCaching();
/*0119*/
/*0120*/ /*=========================================================================
/*0121./ * Constructors/destructors for individual icache entries
/*0122./ *=======================================================================*/
/*0123*/
/*0124*/ int createInlineCacheEntry(cell* contents, BYTE* originalCode);
/*0125*/
/*0126*/ /*=========================================================================
/*0127./ * Operations on individual icache entries
/*0128./ *=======================================================================*/
/*0129*/
/*0130*/ ICACHE getInlineCache(int index);
/*0131*/
/*0132*/ /*=========================================================================
/*0133./ * Macro for high performance!
/*0134./ *=======================================================================*/
/*0135*/
/*0154*/#define REPLACE_BYTECODE(ip, bytecode) *ip = bytecode;
/*0155*/
/*0156*/#define CREATE_CACHE_ENTRY(cellp, ip) \
/*0157*/ iCacheIndex = createInlineCacheEntry((cell*)cellp, ip);
/*0160*/
/*0161*/#define GETINLINECACHE(index) (&InlineCache[index])
/*0162*/
/*0163*/#else
/*0164*/
/*0165*/# define InitializeInlineCaching()
/*0166*/# define FinalizeInlineCaching()
/*0167*/
/*0168*/# define createInlineCacheEntry(contents, originalCode) 0
/*0169*/# define getInlineCache(index) NULL
/*0170*/
/*0171*/#endif /* ENABLEFASTBYTECODES */
/*0172*/
/*0173*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -