00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.8 $ */ 00002 /* Copyright (c) 2006, Sun Microsystems, Inc. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 00006 following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00009 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 00010 disclaimer in the documentation and/or other materials provided with the distribution. 00011 * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 00012 from this software without specific prior written permission. 00013 00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00020 00021 00022 */ 00023 00024 00025 // proxy objects are handles to external data. 00026 00027 // memory layout: 00028 // [header ] 00029 // [klass_field ] 00030 // [pointer ] 00031 00032 const pointer_no = sizeof(memOopDesc)/oopSize; 00033 const pointer_offset = sizeof(memOopDesc) - Mem_Tag; 00034 00035 class proxyOopDesc: public memOopDesc { 00036 private: 00037 void* _pointer; 00038 protected: 00039 proxyOopDesc* addr() const { return (proxyOopDesc*)memOopDesc::addr(); } 00040 00041 public: 00042 friend proxyOop as_proxyOop(void* p) { return proxyOop(as_memOop(p)); } 00043 00044 // sizing 00045 static int header_size() { return sizeof(proxyOopDesc)/oopSize; } 00046 00047 void* get_pointer() const { return addr()->_pointer; } 00048 void set_pointer(void *ptr) { addr()->_pointer = ptr; } 00049 00050 void null_pointer() { set_pointer(NULL); } 00051 00052 bool is_null() const { return get_pointer() == NULL; } 00053 bool is_allOnes() const { return get_pointer() == (void*) -1; } 00054 00055 smi foreign_hash() const { return smi(get_pointer()) >> Tag_Size; } 00056 00057 bool same_pointer_as(proxyOop x) const { 00058 return get_pointer() == x->get_pointer(); 00059 } 00060 00061 void bootstrap_object(bootstrap* st); 00062 00063 private: 00064 unsigned char* addr_at(int offset) const { 00065 return ((unsigned char*) get_pointer()) + offset; 00066 } 00067 public: 00068 unsigned char byte_at(int offset) const { 00069 return *addr_at(offset); 00070 } 00071 void byte_at_put(int offset, unsigned char c) { 00072 *addr_at(offset) = c; 00073 } 00074 doubleByte doubleByte_at(int offset) const { 00075 return *((doubleByte*) addr_at(offset)); 00076 } 00077 void doubleByte_at_put(int offset, doubleByte db) { 00078 *((doubleByte*) addr_at(offset)) = db; 00079 } 00080 long long_at(int offset) const { 00081 return *((long*) addr_at(offset)); 00082 } 00083 void long_at_put(int offset, long l) { 00084 *((long*) addr_at(offset)) = l; 00085 } 00086 00087 float float_at(int offset) const { 00088 return *((float*) addr_at(offset)); 00089 } 00090 void float_at_put(int offset, float f) { 00091 *((float*) addr_at(offset)) = f; 00092 } 00093 00094 double double_at(int offset) const { 00095 return *((double*) addr_at(offset)); 00096 } 00097 void double_at_put(int offset, double d) { 00098 *((double*) addr_at(offset)) = d; 00099 } 00100 00101 friend proxyKlass; 00102 };