dByteArrayOop.cpp

Go to the documentation of this file.
00001 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.19 $ */
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 # include "incls/_precompiled.incl"
00025 # include "incls/_dByteArrayOop.cpp.incl"
00026 
00027 bool doubleByteArrayOopDesc::verify() {
00028   bool flag = memOopDesc::verify();
00029   if (flag) {
00030     int l = length();
00031     if (l < 0) {
00032       error("doubleByteArrayOop %#lx has negative length", this);
00033       flag = false;
00034     }
00035   }
00036   return flag;
00037 }
00038 
00039 void doubleByteArrayOopDesc::bootstrap_object(bootstrap* st) {
00040   memOopDesc::bootstrap_object(st);
00041   st->read_oop(length_addr());
00042   for (int index = 1; index <= length(); index++)
00043     doubleByte_at_put(index, st->read_doubleByte());
00044 }
00045 
00046 inline int sub_sign(int a, int b) {
00047   if (a < b) return -1;
00048   if (a > b) return  1;
00049   return 0;
00050 }
00051 
00052 inline int compare_as_doubleBytes(const doubleByte* a, const doubleByte* b) {
00053   // machine dependent code; little endian code
00054   if (a[0] - b[0]) return sub_sign(a[0], b[0]);
00055   return sub_sign(a[1], b[1]);
00056 }
00057 
00058 int doubleByteArrayOopDesc::compare(doubleByteArrayOop arg) {
00059   // Get the addresses of the length fields
00060   const unsigned int* a = (const unsigned int*) length_addr();
00061   const unsigned int* b = (const unsigned int*) arg->length_addr();
00062 
00063   // Get the word sizes of the arays
00064   int a_size = roundTo(smiOop(*a++)->value() * sizeof(doubleByte), sizeof(int)) / sizeof(int);
00065   int b_size = roundTo(smiOop(*b++)->value() * sizeof(doubleByte), sizeof(int)) / sizeof(int);
00066 
00067   const unsigned int* a_end = a + min(a_size, b_size);
00068   while(a < a_end) {
00069     if (*b++ != *a++) 
00070       return compare_as_doubleBytes((const doubleByte*) (a-1), (const doubleByte*) (b-1));
00071   }
00072   return sub_sign(a_size, b_size);
00073 }
00074 
00075 /*
00076 int doubleByteArrayOopDesc::compare(doubleByteArrayOop arg) {
00077   // Get the addresses of the length fields
00078   int         len_a = length();
00079   doubleByte* a     = doubleBytes();
00080 
00081   int         len_b = arg->length();
00082   doubleByte* b     = arg->doubleBytes();
00083 
00084   doubleByte* end = len_a <= len_b ? a + len_a : b + len_b;
00085 
00086   while(a < end) {
00087     int result = *a++ - *b++;
00088     if (result != 0) {
00089       if (result < 0) return -1;
00090       if (result > 0) return  1;
00091     }
00092   }
00093   return sub_sign(len_a, len_b);
00094 }
00095 */
00096 
00097 int doubleByteArrayOopDesc::hash_value() {
00098   int len = length();
00099   int result;
00100 
00101   if (len == 0) {
00102     result = 1;
00103   } else if (len == 1) {
00104     result = doubleByte_at(1);
00105   } else {
00106     unsigned int val;
00107     val = doubleByte_at(1);
00108     val = (val << 3) ^ (doubleByte_at(2)         ^ val);
00109     val = (val << 3) ^ (doubleByte_at(len)       ^ val);
00110     val = (val << 3) ^ (doubleByte_at(len-1)     ^ val);
00111     val = (val << 3) ^ (doubleByte_at(len/2 + 1) ^ val);
00112     val = (val << 3) ^ (len                      ^ val);
00113     result = markOopDesc::masked_hash(val);
00114   }
00115   return result == 0 ? 1 : result;
00116 }
00117 
00118 
00119 bool doubleByteArrayOopDesc::copy_null_terminated(char* buffer, int max_length) {
00120   int len = length();
00121   bool is_truncated = false;
00122   if (len >= max_length) {
00123     len = max_length - 1;
00124     is_truncated = true;
00125   }
00126   for (int index = 0; index < len; index++)
00127     buffer[index] = (char) doubleByte_at(index+1);
00128   buffer[len]= '\0';
00129   return is_truncated;
00130 }
00131 
00132 char* doubleByteArrayOopDesc::as_string() {
00133   int len = length();
00134   char* str = NEW_RESOURCE_ARRAY(char, len+1);
00135   for (int index = 0; index <len; index++) {
00136     str[index] = (char) doubleByte_at(index+1);
00137   }
00138   str[index] = '\0';
00139   return str;
00140 }
00141 

Generated on Mon Oct 9 13:37:08 2006 for Strongtalk VM by  doxygen 1.4.7