src/share/vm/oops/symbol.hpp

changeset 3682
fc9d8850ab8b
parent 2708
1d1603768966
child 4037
da91efe96a93
     1.1 --- a/src/share/vm/oops/symbol.hpp	Thu Mar 15 13:37:13 2012 +0100
     1.2 +++ b/src/share/vm/oops/symbol.hpp	Fri Mar 23 11:16:05 2012 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -27,6 +27,7 @@
    1.11  
    1.12  #include "utilities/utf8.hpp"
    1.13  #include "memory/allocation.hpp"
    1.14 +#include "runtime/atomic.hpp"
    1.15  
    1.16  // A Symbol is a canonicalized string.
    1.17  // All Symbols reside in global SymbolTable and are reference counted.
    1.18 @@ -95,7 +96,7 @@
    1.19  // TempNewSymbol (passed in as a parameter) so the reference count on its symbol
    1.20  // will be decremented when it goes out of scope.
    1.21  
    1.22 -class Symbol : public CHeapObj {
    1.23 +class Symbol : public ResourceObj {
    1.24    friend class VMStructs;
    1.25    friend class SymbolTable;
    1.26    friend class MoveSymbols;
    1.27 @@ -111,7 +112,7 @@
    1.28    };
    1.29  
    1.30    static int object_size(int length) {
    1.31 -    size_t size = heap_word_size(sizeof(Symbol) + length);
    1.32 +    size_t size = heap_word_size(sizeof(Symbol) + (length > 0 ? length - 1 : 0));
    1.33      return align_object_size(size);
    1.34    }
    1.35  
    1.36 @@ -120,28 +121,25 @@
    1.37      _body[index] = value;
    1.38    }
    1.39  
    1.40 -  Symbol(const u1* name, int length);
    1.41 -  void* operator new(size_t size, int len);
    1.42 +  Symbol(const u1* name, int length, int refcount);
    1.43 +  void* operator new(size_t size, int len, TRAPS);
    1.44 +  void* operator new(size_t size, int len, Arena* arena, TRAPS);
    1.45  
    1.46   public:
    1.47    // Low-level access (used with care, since not GC-safe)
    1.48    const jbyte* base() const { return &_body[0]; }
    1.49  
    1.50 -  int object_size() { return object_size(utf8_length()); }
    1.51 +  int object_size()         { return object_size(utf8_length()); }
    1.52  
    1.53    // Returns the largest size symbol we can safely hold.
    1.54 -  static int max_length() {
    1.55 -    return max_symbol_length;
    1.56 -  }
    1.57 +  static int max_length()   { return max_symbol_length; }
    1.58  
    1.59 -  int identity_hash() {
    1.60 -    return _identity_hash;
    1.61 -  }
    1.62 +  int identity_hash()       { return _identity_hash; }
    1.63  
    1.64    // Reference counting.  See comments above this class for when to use.
    1.65 -  int refcount() const { return _refcount; }
    1.66 -  void increment_refcount();
    1.67 -  void decrement_refcount();
    1.68 +  int refcount() const      { return _refcount; }
    1.69 +  inline void increment_refcount();
    1.70 +  inline void decrement_refcount();
    1.71  
    1.72    int byte_at(int index) const {
    1.73      assert(index >=0 && index < _length, "symbol index overflow");
    1.74 @@ -220,4 +218,26 @@
    1.75   return (((uintptr_t)this < (uintptr_t)other) ? -1
    1.76     : ((uintptr_t)this == (uintptr_t) other) ? 0 : 1);
    1.77  }
    1.78 +
    1.79 +inline void Symbol::increment_refcount() {
    1.80 +  // Only increment the refcount if positive.  If negative either
    1.81 +  // overflow has occurred or it is a permanent symbol in a read only
    1.82 +  // shared archive.
    1.83 +  if (_refcount >= 0) {
    1.84 +    Atomic::inc(&_refcount);
    1.85 +    NOT_PRODUCT(Atomic::inc(&_total_count);)
    1.86 +  }
    1.87 +}
    1.88 +
    1.89 +inline void Symbol::decrement_refcount() {
    1.90 +  if (_refcount >= 0) {
    1.91 +    Atomic::dec(&_refcount);
    1.92 +#ifdef ASSERT
    1.93 +    if (_refcount < 0) {
    1.94 +      print();
    1.95 +      assert(false, "reference count underflow for symbol");
    1.96 +    }
    1.97 +#endif
    1.98 +  }
    1.99 +}
   1.100  #endif // SHARE_VM_OOPS_SYMBOL_HPP

mercurial