1 /* Copyright 1994, LongView Technologies L.L.C. $Revision: 1.13 $ */
2 /* Copyright (c) 2006, Sun Microsystems, Inc.
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6 following conditions are met:
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
10 disclaimer in the documentation and/or other materials provided with the distribution.
11 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived
12 from this software without specific prior written permission.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
15 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
16 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
18 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
19 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
26 # define OOPNCODE_FROM(fieldName, p) \
27 ((OopNCode*)((char*)p - (char*)&((OopNCode*)NULL)->fieldName))
29 // NCodeBase is the superclass of all things containing native code.
31 class NCodeBase
: public PrintableCHeapObj
{
33 int _instsLen
; // instruction length in bytes
35 void* operator new(size_t size
) {
36 Unused(size
); SubclassResponsibility(); return NULL
; }
38 virtual char* insts() const = 0; // beginning of instructions part
39 virtual int size() const = 0; // size in bytes
40 int instsLen() const { return _instsLen
; }
41 char* instsEnd() const { return insts() + instsLen(); }
42 bool contains(void* p
) const { return (void*)insts() <= p
&& p
< (void*)instsEnd(); }
44 virtual bool isNMethod() const { return false; }
45 virtual bool isPIC() const { return false; }
46 //virtual bool isCountStub() const { return false; }
47 //virtual bool isAgingStub() const { return false; }
49 virtual void moveTo(void* to
, int size
) = 0; // (possibly overlapping) copy
50 virtual void relocate() {};
51 virtual void verify() = 0;
53 void verify2(char* name
);
57 // OopNCode is the base class of all code containing oop references embedded
58 // in the code (e.g. "load constant" instructions).
60 class OopNCode
: public NCodeBase
{
62 void check_store(oop x
, char *bound
) {
63 if (Universe::new_gen
.is_new(x
, bound
)) remember(); }
64 int _locsLen
; // relocation info length (bytes)
67 relocInfo
* locs() const { return (relocInfo
*) instsEnd();}
68 int locsLen() const { return _locsLen
;}
69 relocInfo
* locsEnd() const { return (relocInfo
*) ((char*)locs() + _locsLen
);}
71 virtual bool isNMethod() const { return false; }
73 // Memory operations: return true if need to invalidate instruction cache
74 virtual bool switch_pointers(oop from
, oop to
,
75 GrowableArray
<nmethod
*>* nmethods_to_invalidate
);
79 virtual void verify();
82 NCodeBase
* findThing(void* addr
); // returns NULL if addr not in a zone