1 /* Copyright 1994, 1995 LongView Technologies L.L.C. $Revision: 1.19 $ */
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
24 # include "incls/_precompiled.incl"
25 # include "incls/_dByteArrayOop.cpp.incl"
27 bool doubleByteArrayOopDesc::verify() {
28 bool flag
= memOopDesc::verify();
32 error("doubleByteArrayOop %#lx has negative length", this);
39 void doubleByteArrayOopDesc::bootstrap_object(bootstrap
* st
) {
40 memOopDesc::bootstrap_object(st
);
41 st
->read_oop(length_addr());
42 for (int index
= 1; index
<= length(); index
++)
43 doubleByte_at_put(index
, st
->read_doubleByte());
46 inline int sub_sign(int a
, int b
) {
52 inline int compare_as_doubleBytes(const doubleByte
* a
, const doubleByte
* b
) {
53 // machine dependent code; little endian code
54 if (a
[0] - b
[0]) return sub_sign(a
[0], b
[0]);
55 return sub_sign(a
[1], b
[1]);
58 int doubleByteArrayOopDesc::compare(doubleByteArrayOop arg
) {
59 // Get the addresses of the length fields
60 const unsigned int* a
= (const unsigned int*) length_addr();
61 const unsigned int* b
= (const unsigned int*) arg
->length_addr();
63 // Get the word sizes of the arays
64 int a_size
= roundTo(smiOop(*a
++)->value() * sizeof(doubleByte
), sizeof(int)) / sizeof(int);
65 int b_size
= roundTo(smiOop(*b
++)->value() * sizeof(doubleByte
), sizeof(int)) / sizeof(int);
67 const unsigned int* a_end
= a
+ min(a_size
, b_size
);
70 return compare_as_doubleBytes((const doubleByte
*) (a
-1), (const doubleByte
*) (b
-1));
72 return sub_sign(a_size
, b_size
);
76 int doubleByteArrayOopDesc::compare(doubleByteArrayOop arg) {
77 // Get the addresses of the length fields
79 doubleByte* a = doubleBytes();
81 int len_b = arg->length();
82 doubleByte* b = arg->doubleBytes();
84 doubleByte* end = len_a <= len_b ? a + len_a : b + len_b;
87 int result = *a++ - *b++;
89 if (result < 0) return -1;
90 if (result > 0) return 1;
93 return sub_sign(len_a, len_b);
97 int doubleByteArrayOopDesc::hash_value() {
103 } else if (len
== 1) {
104 result
= doubleByte_at(1);
107 val
= doubleByte_at(1);
108 val
= (val
<< 3) ^ (doubleByte_at(2) ^ val
);
109 val
= (val
<< 3) ^ (doubleByte_at(len
) ^ val
);
110 val
= (val
<< 3) ^ (doubleByte_at(len
-1) ^ val
);
111 val
= (val
<< 3) ^ (doubleByte_at(len
/2 + 1) ^ val
);
112 val
= (val
<< 3) ^ (len
^ val
);
113 result
= markOopDesc::masked_hash(val
);
115 return result
== 0 ? 1 : result
;
119 bool doubleByteArrayOopDesc::copy_null_terminated(char* buffer
, int max_length
) {
121 bool is_truncated
= false;
122 if (len
>= max_length
) {
123 len
= max_length
- 1;
126 for (int index
= 0; index
< len
; index
++)
127 buffer
[index
] = (char) doubleByte_at(index
+1);
132 char* doubleByteArrayOopDesc::as_string() {
134 char* str
= NEW_RESOURCE_ARRAY(char, len
+1);
135 for (int index
= 0; index
<len
; index
++) {
136 str
[index
] = (char) doubleByte_at(index
+1);