< prev index next >

src/hotspot/share/adlc/forms.cpp

Print this page




  31 Arena *Form::generate_arena() {
  32   return (new Arena);
  33 }
  34 
  35 //------------------------------NameList---------------------------------------
  36 // reserved user-defined string
  37 const char  *NameList::_signal   = "$$SIGNAL$$";
  38 const char  *NameList::_signal2  = "$$SIGNAL2$$";
  39 const char  *NameList::_signal3  = "$$SIGNAL3$$";
  40 
  41 // Constructor and Destructor
  42 NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
  43   _names = (const char**) AllocateHeap(_max*sizeof(char*));
  44 }
  45 NameList::~NameList() {
  46   // The following free is a double-free, and crashes the program:
  47   //free(_names);                   // not owner of strings
  48 }
  49 
  50 void   NameList::addName(const char *name) {
  51   if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));


  52   _names[_cur++] = name;
  53 }
  54 
  55 void   NameList::add_signal() {
  56   addName( _signal );
  57 }
  58 void   NameList::clear() {
  59   _cur   = 0;
  60   _iter  = 0;
  61   _justReset = true;
  62   // _max   = 4; Already allocated
  63 }
  64 
  65 int    NameList::count()  const { return _cur; }
  66 
  67 void   NameList::reset()   { _iter = 0; _justReset = true;}
  68 const char  *NameList::iter()    {
  69   if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}
  70   else return (_iter <_cur-1 ? _names[++_iter] : NULL);
  71 }




  31 Arena *Form::generate_arena() {
  32   return (new Arena);
  33 }
  34 
  35 //------------------------------NameList---------------------------------------
  36 // reserved user-defined string
  37 const char  *NameList::_signal   = "$$SIGNAL$$";
  38 const char  *NameList::_signal2  = "$$SIGNAL2$$";
  39 const char  *NameList::_signal3  = "$$SIGNAL3$$";
  40 
  41 // Constructor and Destructor
  42 NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
  43   _names = (const char**) AllocateHeap(_max*sizeof(char*));
  44 }
  45 NameList::~NameList() {
  46   // The following free is a double-free, and crashes the program:
  47   //free(_names);                   // not owner of strings
  48 }
  49 
  50 void   NameList::addName(const char *name) {
  51   if (_cur == _max) {
  52     _names = (const char**) ReAllocateHeap(_names, (_max *=2)*sizeof(char*));
  53   }
  54   _names[_cur++] = name;
  55 }
  56 
  57 void   NameList::add_signal() {
  58   addName( _signal );
  59 }
  60 void   NameList::clear() {
  61   _cur   = 0;
  62   _iter  = 0;
  63   _justReset = true;
  64   // _max   = 4; Already allocated
  65 }
  66 
  67 int    NameList::count()  const { return _cur; }
  68 
  69 void   NameList::reset()   { _iter = 0; _justReset = true;}
  70 const char  *NameList::iter()    {
  71   if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}
  72   else return (_iter <_cur-1 ? _names[++_iter] : NULL);
  73 }


< prev index next >