/* Sun-$Revision: 23.5 $ */
/* Copyright 1992-9 Sun Microsystems, Inc. and Stanford University.
See the LICENSE file for license information. */
# pragma interface
inline smi lengthWords(smi l) { return roundTo((l), oopSize) / oopSize; }
struct byteVectorOopClass: slotsOopClass {
// instance variables
smiOop _len;
char* _bytes;
// constructor
friend byteVectorOop as_byteVectorOop(void* p) {
return byteVectorOop(as_slotsOop(p)); }
// accessors
byteVectorOopClass* addr() {
return (byteVectorOopClass*) slotsOopClass::addr(); }
smi length() { return addr()->_len->value(); }
void set_length(smi len) { addr()->_len = as_smiOop(len); }
smi lengthWords() { return ::lengthWords(length()); }
char* bytes(fint which = 0) { return &addr()->_bytes[which]; }
void set_bytes(char* bytes) { addr()->_bytes = bytes; }
char byte_at(fint which) {
assert(which >= 0 && which < length(), "index out of bounds");
return *bytes(which); }
void byte_at_put(fint which, char contents) {
assert(which >= 0 && which < length(), "index out of bounds");
*bytes(which) = contents; }
// allocators
byteVectorOop copy(fint size, bool mustAllocate, oop genObj, bool cs);
byteVectorOop copy(bool mustAllocate= true, oop genObj= NULL, bool cs= true)
{ return copy(size(), mustAllocate, genObj, cs); }
byteVectorOop grow_bytes(fint delta, bool mustAllocate);
byteVectorOop shrink_bytes(fint delta, bool mustAllocate);
byteVectorOop insert(fint size, fint change_point, fint delta,
bool mustAllocate= true, bool sameGen= false);
byteVectorOop remove(fint size, fint change_point, fint delta,
bool mustAllocate= true, bool sameGen= false);
# ifdef UNUSED
byteVectorOop clone(bool mustAllocate= true) {
return byteVectorOop(slotsOopClass::clone(mustAllocate)); }
# endif
byteVectorOop cloneSize(fint length, bool mustAllocate= true,
oop filler= NULL) {
return byteVectorOop(slotsOopClass::cloneSize(length, mustAllocate,
filler)); }
// creation operations
friend byteVectorOop create_byteVector(oop parent);
friend byteVectorOop create_byteVector(fint size);
// memory operations
byteVectorOop scavenge(fint size);
void relocate_bytes(space* s);
bool verify();
bool verifyBytesPart(char*& b);
// C-string operations
char *copy_null_terminated(int &Clength);
// Copy the bytes() part. Always add trailing '\0'. If byte vector
// contains '\0', these will be escaped in the copy, i.e. "....\0...".
// Clength is set to length of the copy (may be longer due to escaping).
// Presence of null chars can be detected by comparing Clength to length().
char *copy_null_terminated() {
int ignore;
return copy_null_terminated(ignore);
}
char *copy_c_heap_null_terminated();
// Identical to copy_null_terminated but allocates the resulting string
// in the C heap instead of in the resource area.
bool equals(char* name, int32 len) {
return len == length() &&
compare_bytes(bytes(), length(), name, len) == 0; }
bool equals(byteVectorOop s) {
return equals(s->bytes(), s->length()); }
void string_print() { lprintf_string(length(), bytes());}
void string_print(fint offset, fint len) { lprintf_string( len, bytes()+offset); }
// primitives
friend oop bv_at_prim(oop rcvr, oop index);
friend oop bv_at_put_prim(oop rcvr, oop index, oop cval);
friend oop bv_size_prim(oop rcvr);
friend oop bv_compare_prim(oop rcvr, oop arg);
oop bv_concatenate_prim(byteVectorOop arg, byteVectorOop proto, void *FH);
oop bv_clone_prim(smi size, u_char filler, void *FH); // Caller must handle size < 0.
oop string_print_prim();
oop string_print_on_prim(oop fileName);
oop string_canonicalize_prim();
oop run_script_prim();
oop parseObject_prim(char* fn, oop errorObj, void *FH);
oop parseObjectIntoPositionTable_prim();
oop write_snapshot_prim(void *FH);
// documentation primitive
oop primitive_documentation_prim(void *FH);
// primitive to set system verification options
byteVectorOop verify_opts_prim();
// compiler support
friend int32 byteVector_len_offset() {
return int32(&byteVectorOop(0)->addr()->_len); }
friend int32 byteVector_bytes_offset() {
return int32(&byteVectorOop(0)->addr()->_bytes); }
};