00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.9 $ */ 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 // doubleByteArrays are arrays containing double bytes 00025 00026 // memory layout: 00027 // [header ] 00028 // [klass_field ] 00029 // [instVars ]* 00030 // [length ] offset 00031 00032 class doubleByteArrayOopDesc: public memOopDesc { 00033 public: 00034 // constructor 00035 friend doubleByteArrayOop as_doubleByteArrayOop(void* p) { 00036 return doubleByteArrayOop(as_memOop(p)); } 00037 00038 void bootstrap_object(bootstrap* st); 00039 00040 // accessors 00041 doubleByteArrayOopDesc* addr() const { 00042 return (doubleByteArrayOopDesc*) memOopDesc::addr(); } 00043 00044 bool is_within_bounds(int index) const { return 1 <= index && index <= length(); } 00045 00046 oop* addr_as_oops() const { return (oop*)addr(); } 00047 00048 // returns the location of the length field 00049 oop* length_addr() const { 00050 return &addr_as_oops()[blueprint()->non_indexable_size()]; 00051 } 00052 00053 smi length() const { 00054 oop len = *length_addr(); 00055 assert(len->is_smi(), "length of indexable should be smi"); 00056 return smiOop(len)->value();} 00057 00058 void set_length(smi len) { 00059 *length_addr() = (oop) as_smiOop(len); } 00060 00061 // returns the location where the double bytes start 00062 doubleByte* doubleBytes() const { 00063 return (doubleByte*) &length_addr()[1]; 00064 } 00065 00066 doubleByte* doubleByte_at_addr(int which) const { 00067 assert(which > 0 && which <= length(), "index out of bounds"); 00068 return &doubleBytes()[which - 1]; 00069 } 00070 00071 doubleByte doubleByte_at(int which) const { 00072 return *doubleByte_at_addr(which); } 00073 00074 void doubleByte_at_put(int which, doubleByte contents) { 00075 *doubleByte_at_addr(which) = contents; } 00076 00077 // three way compare 00078 int compare(doubleByteArrayOop arg); 00079 00080 // Returns the hash value for the string 00081 int hash_value(); 00082 00083 // copy string to buffer as null terminated ascii string. 00084 bool copy_null_terminated(char* buffer, int max_length); 00085 char* as_string(); 00086 00087 // memory operations 00088 bool verify(); 00089 00090 friend doubleByteArrayKlass; 00091 }; 00092