00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00060 const unsigned int* a = (const unsigned int*) length_addr();
00061 const unsigned int* b = (const unsigned int*) arg->length_addr();
00062
00063
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
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
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