byteArrayOop.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996 LongView Technologies L.L.C. $Revision: 1.24 $ */
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 class Integer;
00025 
00026 // byteArrays are arrays containing bytes
00027 //
00028 // memory layout:
00029 //    [header      ]
00030 //    [klass_field ]
00031 //    [instVars    ]*
00032 //    [length      ]
00033 //    [bytes       ]* = bytes(1) .. bytes(length) + padding
00034 
00035 class byteArrayOopDesc: public memOopDesc {
00036   public:
00037   // constructor
00038   friend byteArrayOop as_byteArrayOop(void* p);
00039 
00040   void bootstrap_object(bootstrap* st);
00041 
00042 
00043   // accessors
00044   byteArrayOopDesc* addr() const {
00045     return (byteArrayOopDesc*) memOopDesc::addr(); }
00046 
00047   bool is_within_bounds(int index) const { return 1 <= index && index <= length(); }
00048 
00049   oop* addr_as_oops() const { return (oop*)addr(); }
00050 
00051   oop* length_addr() const  {
00052     return &addr_as_oops()[blueprint()->non_indexable_size()];
00053   }
00054 
00055   smi length() const {
00056     oop len = *length_addr();
00057     assert(len->is_smi(), "length of indexable should be smi");
00058     return smiOop(len)->value();}
00059 
00060   void set_length(smi len) {
00061     *length_addr() = (oop) as_smiOop(len); }
00062  
00063   u_char* bytes() const {
00064     return (u_char*) &length_addr()[1];  
00065   }
00066 
00067   char*   chars() const { return (char*) bytes(); }
00068 
00069   u_char* byte_at_addr(int which) const {
00070     assert(which > 0 && which <= length(), "index out of bounds");
00071     return &bytes()[which - 1];
00072   }
00073 
00074   u_char byte_at(int which) const {
00075     return *byte_at_addr(which); }
00076   void byte_at_put(int which, u_char contents) {
00077     *byte_at_addr(which) = contents; }
00078 
00079 
00080   // support for large integers
00081 
00082   Integer& number() { return *((Integer*)bytes()); }
00083 
00084 
00085   // memory operations
00086   bool verify();
00087 
00088 
00089   // C-string operations
00090 
00091   char *copy_null_terminated(int &Clength);
00092     // Copy the bytes() part. Always add trailing '\0'. If byte array
00093     // contains '\0', these will be escaped in the copy, i.e. "....\0...".
00094     // Clength is set to length of the copy (may be longer due to escaping).
00095     // Presence of null chars can be detected by comparing Clength to length().
00096 
00097   bool copy_null_terminated(char* buffer, int max_length);
00098 
00099   char *copy_null_terminated() {
00100     int ignore;
00101     return copy_null_terminated(ignore);
00102   }
00103 
00104   char *copy_c_heap_null_terminated();
00105     // Identical to copy_null_terminated but allocates the resulting string
00106     // in the C heap instead of in the resource area.
00107 
00108   bool equals(char* name) {
00109     return equals(name, strlen(name));
00110   }
00111 
00112   bool equals(char* name, int len) {
00113     return len == length() && strncmp(chars(), name, len) == 0; }
00114   bool equals(byteArrayOop s) {
00115     return equals(s->chars(), s->length()); }
00116 
00117   // three way compare
00118   int compare(byteArrayOop arg);
00119   int compare_doubleBytes(doubleByteArrayOop arg);
00120 
00121   // Returns the hash value for the string.
00122   int hash_value();
00123 
00124   // resource allocated print string
00125   char* as_string();
00126 
00127   // Selector specific operations.
00128   int number_of_arguments() const;
00129   bool is_unary()           const;
00130   bool is_binary()          const;
00131   bool is_keyword()         const;
00132 
00133   friend byteArrayKlass;
00134 };
00135 
00136 
00137 

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