annotate src/share/vm/adlc/forms.cpp @ 5663:1dcea64e9f00

8024830: SEGV in org.apache.lucene.codecs.compressing.CompressingTermVectorsReader.get Summary: Exclude last input argument's stack slots from vector's spilling masks. Reviewed-by: iveresov
author kvn
date Mon, 11 Nov 2013 11:53:33 -0800
parents 8e47bac5643a
children
rev   line source
duke@0 1 /*
kvn@3447 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // FORMS.CPP - Definitions for ADL Parser Generic & Utility Forms Classes
duke@0 26 #include "adlc.hpp"
duke@0 27
duke@0 28 //------------------------------Static Initializers----------------------------
duke@0 29 // allocate arena used by forms
duke@0 30 Arena *Form::arena = Form::generate_arena(); // = Form::generate_arena();
duke@0 31 Arena *Form::generate_arena() {
duke@0 32 return (new Arena);
duke@0 33 }
duke@0 34
duke@0 35 //------------------------------NameList---------------------------------------
duke@0 36 // reserved user-defined string
duke@0 37 const char *NameList::_signal = "$$SIGNAL$$";
never@415 38 const char *NameList::_signal2 = "$$SIGNAL2$$";
never@415 39 const char *NameList::_signal3 = "$$SIGNAL3$$";
duke@0 40
duke@0 41 // Constructor and Destructor
duke@0 42 NameList::NameList() : _cur(0), _max(4), _iter(0), _justReset(true) {
duke@0 43 _names = (const char**)malloc(_max*sizeof(char*));
duke@0 44 }
duke@0 45 NameList::~NameList() {
duke@0 46 // The following free is a double-free, and crashes the program:
duke@0 47 //free(_names); // not owner of strings
duke@0 48 }
duke@0 49
duke@0 50 void NameList::addName(const char *name) {
duke@0 51 if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));
duke@0 52 _names[_cur++] = name;
duke@0 53 }
duke@0 54
duke@0 55 void NameList::add_signal() {
duke@0 56 addName( _signal );
duke@0 57 }
duke@0 58 void NameList::clear() {
duke@0 59 _cur = 0;
duke@0 60 _iter = 0;
duke@0 61 _justReset = true;
duke@0 62 // _max = 4; Already allocated
duke@0 63 }
duke@0 64
duke@0 65 int NameList::count() const { return _cur; }
duke@0 66
duke@0 67 void NameList::reset() { _iter = 0; _justReset = true;}
duke@0 68 const char *NameList::iter() {
duke@0 69 if (_justReset) {_justReset=false; return (_iter < _cur ? _names[_iter] : NULL);}
duke@0 70 else return (_iter <_cur-1 ? _names[++_iter] : NULL);
duke@0 71 }
duke@0 72 const char *NameList::current() { return (_iter < _cur ? _names[_iter] : NULL); }
twisti@624 73 const char *NameList::peek(int skip) { return (_iter + skip < _cur ? _names[_iter + skip] : NULL); }
duke@0 74
duke@0 75 // Return 'true' if current entry is signal
duke@0 76 bool NameList::current_is_signal() {
duke@0 77 const char *entry = current();
duke@0 78 return is_signal(entry);
duke@0 79 }
duke@0 80
duke@0 81 // Return true if entry is a signal
duke@0 82 bool NameList::is_signal(const char *entry) {
duke@0 83 return ( (strcmp(entry,NameList::_signal) == 0) ? true : false);
duke@0 84 }
duke@0 85
duke@0 86 // Search for a name in the list
duke@0 87 bool NameList::search(const char *name) {
duke@0 88 const char *entry;
duke@0 89 for(reset(); (entry = iter()) != NULL; ) {
duke@0 90 if(!strcmp(entry,name)) return true;
duke@0 91 }
duke@0 92 return false;
duke@0 93 }
duke@0 94
duke@0 95 // Return index of name in list
duke@0 96 int NameList::index(const char *name) {
duke@0 97 int cnt = 0;
duke@0 98 const char *entry;
duke@0 99 for(reset(); (entry = iter()) != NULL; ) {
duke@0 100 if(!strcmp(entry,name)) return cnt;
duke@0 101 cnt++;
duke@0 102 }
duke@0 103 return Not_in_list;
duke@0 104 }
duke@0 105
duke@0 106 // Return name at index in list
duke@0 107 const char *NameList::name(intptr_t index) {
duke@0 108 return ( index < _cur ? _names[index] : NULL);
duke@0 109 }
duke@0 110
duke@0 111 void NameList::dump() { output(stderr); }
duke@0 112
duke@0 113 void NameList::output(FILE *fp) {
duke@0 114 fprintf(fp, "\n");
duke@0 115
duke@0 116 // Run iteration over all entries, independent of position of iterator.
duke@0 117 const char *name = NULL;
duke@0 118 int iter = 0;
duke@0 119 bool justReset = true;
duke@0 120
duke@0 121 while( ( name = (justReset ?
duke@0 122 (justReset=false, (iter < _cur ? _names[iter] : NULL)) :
duke@0 123 (iter < _cur-1 ? _names[++iter] : NULL)) )
duke@0 124 != NULL ) {
duke@0 125 fprintf( fp, " %s,\n", name);
duke@0 126 }
duke@0 127 fprintf(fp, "\n");
duke@0 128 }
duke@0 129
duke@0 130 //------------------------------NameAndList------------------------------------
duke@0 131 // Storage for a name and an associated list of names
duke@0 132 NameAndList::NameAndList(char *name) : _name(name) {
duke@0 133 }
duke@0 134 NameAndList::~NameAndList() {
duke@0 135 }
duke@0 136
duke@0 137 // Add to entries in list
duke@0 138 void NameAndList::add_entry(const char *entry) {
duke@0 139 _list.addName(entry);
duke@0 140 }
duke@0 141
duke@0 142 // Access the name and its associated list.
duke@0 143 const char *NameAndList::name() const { return _name; }
duke@0 144 void NameAndList::reset() { _list.reset(); }
duke@0 145 const char *NameAndList::iter() { return _list.iter(); }
duke@0 146
duke@0 147 // Return the "index" entry in the list, zero-based
duke@0 148 const char *NameAndList::operator[](int index) {
duke@0 149 assert( index >= 0, "Internal Error(): index less than 0.");
duke@0 150
duke@0 151 _list.reset();
duke@0 152 const char *entry = _list.iter();
duke@0 153 // Iterate further if it isn't at index 0.
duke@0 154 for ( int position = 0; position != index; ++position ) {
duke@0 155 entry = _list.iter();
duke@0 156 }
duke@0 157
duke@0 158 return entry;
duke@0 159 }
duke@0 160
duke@0 161
duke@0 162 void NameAndList::dump() { output(stderr); }
duke@0 163 void NameAndList::output(FILE *fp) {
duke@0 164 fprintf(fp, "\n");
duke@0 165
duke@0 166 // Output the Name
duke@0 167 fprintf(fp, "Name == %s", (_name ? _name : "") );
duke@0 168
duke@0 169 // Output the associated list of names
duke@0 170 const char *name;
duke@0 171 fprintf(fp, " (");
duke@0 172 for (reset(); (name = iter()) != NULL;) {
duke@0 173 fprintf(fp, " %s,\n", name);
duke@0 174 }
duke@0 175 fprintf(fp, ")");
duke@0 176 fprintf(fp, "\n");
duke@0 177 }
duke@0 178
duke@0 179 //------------------------------Form-------------------------------------------
duke@0 180 OpClassForm *Form::is_opclass() const {
duke@0 181 return NULL;
duke@0 182 }
duke@0 183
duke@0 184 OperandForm *Form::is_operand() const {
duke@0 185 return NULL;
duke@0 186 }
duke@0 187
duke@0 188 InstructForm *Form::is_instruction() const {
duke@0 189 return NULL;
duke@0 190 }
duke@0 191
duke@0 192 MachNodeForm *Form::is_machnode() const {
duke@0 193 return NULL;
duke@0 194 }
duke@0 195
duke@0 196 AttributeForm *Form::is_attribute() const {
duke@0 197 return NULL;
duke@0 198 }
duke@0 199
duke@0 200 Effect *Form::is_effect() const {
duke@0 201 return NULL;
duke@0 202 }
duke@0 203
duke@0 204 ResourceForm *Form::is_resource() const {
duke@0 205 return NULL;
duke@0 206 }
duke@0 207
duke@0 208 PipeClassForm *Form::is_pipeclass() const {
duke@0 209 return NULL;
duke@0 210 }
duke@0 211
duke@0 212 Form::DataType Form::ideal_to_const_type(const char *name) const {
duke@0 213 if( name == NULL ) { return Form::none; }
duke@0 214
duke@0 215 if (strcmp(name,"ConI")==0) return Form::idealI;
duke@0 216 if (strcmp(name,"ConP")==0) return Form::idealP;
coleenp@113 217 if (strcmp(name,"ConN")==0) return Form::idealN;
roland@3724 218 if (strcmp(name,"ConNKlass")==0) return Form::idealNKlass;
duke@0 219 if (strcmp(name,"ConL")==0) return Form::idealL;
duke@0 220 if (strcmp(name,"ConF")==0) return Form::idealF;
duke@0 221 if (strcmp(name,"ConD")==0) return Form::idealD;
duke@0 222 if (strcmp(name,"Bool")==0) return Form::idealI;
duke@0 223
duke@0 224 return Form::none;
duke@0 225 }
duke@0 226
duke@0 227 Form::DataType Form::ideal_to_sReg_type(const char *name) const {
duke@0 228 if( name == NULL ) { return Form::none; }
duke@0 229
duke@0 230 if (strcmp(name,"sRegI")==0) return Form::idealI;
duke@0 231 if (strcmp(name,"sRegP")==0) return Form::idealP;
duke@0 232 if (strcmp(name,"sRegF")==0) return Form::idealF;
duke@0 233 if (strcmp(name,"sRegD")==0) return Form::idealD;
duke@0 234 if (strcmp(name,"sRegL")==0) return Form::idealL;
duke@0 235 return Form::none;
duke@0 236 }
duke@0 237
duke@0 238 Form::DataType Form::ideal_to_Reg_type(const char *name) const {
duke@0 239 if( name == NULL ) { return Form::none; }
duke@0 240
duke@0 241 if (strcmp(name,"RegI")==0) return Form::idealI;
duke@0 242 if (strcmp(name,"RegP")==0) return Form::idealP;
duke@0 243 if (strcmp(name,"RegF")==0) return Form::idealF;
duke@0 244 if (strcmp(name,"RegD")==0) return Form::idealD;
duke@0 245 if (strcmp(name,"RegL")==0) return Form::idealL;
duke@0 246
duke@0 247 return Form::none;
duke@0 248 }
duke@0 249
duke@0 250 // True if 'opType', an ideal name, loads or stores.
duke@0 251 Form::DataType Form::is_load_from_memory(const char *opType) const {
duke@0 252 if( strcmp(opType,"LoadB")==0 ) return Form::idealB;
twisti@624 253 if( strcmp(opType,"LoadUB")==0 ) return Form::idealB;
twisti@558 254 if( strcmp(opType,"LoadUS")==0 ) return Form::idealC;
duke@0 255 if( strcmp(opType,"LoadD")==0 ) return Form::idealD;
duke@0 256 if( strcmp(opType,"LoadD_unaligned")==0 ) return Form::idealD;
duke@0 257 if( strcmp(opType,"LoadF")==0 ) return Form::idealF;
duke@0 258 if( strcmp(opType,"LoadI")==0 ) return Form::idealI;
duke@0 259 if( strcmp(opType,"LoadKlass")==0 ) return Form::idealP;
roland@3724 260 if( strcmp(opType,"LoadNKlass")==0 ) return Form::idealNKlass;
duke@0 261 if( strcmp(opType,"LoadL")==0 ) return Form::idealL;
duke@0 262 if( strcmp(opType,"LoadL_unaligned")==0 ) return Form::idealL;
duke@0 263 if( strcmp(opType,"LoadPLocked")==0 ) return Form::idealP;
duke@0 264 if( strcmp(opType,"LoadP")==0 ) return Form::idealP;
coleenp@113 265 if( strcmp(opType,"LoadN")==0 ) return Form::idealN;
duke@0 266 if( strcmp(opType,"LoadRange")==0 ) return Form::idealI;
duke@0 267 if( strcmp(opType,"LoadS")==0 ) return Form::idealS;
kvn@3447 268 if( strcmp(opType,"LoadVector")==0 ) return Form::idealV;
duke@0 269 assert( strcmp(opType,"Load") != 0, "Must type Loads" );
duke@0 270 return Form::none;
duke@0 271 }
duke@0 272
duke@0 273 Form::DataType Form::is_store_to_memory(const char *opType) const {
duke@0 274 if( strcmp(opType,"StoreB")==0) return Form::idealB;
kvn@3447 275 if( strcmp(opType,"StoreCM")==0) return Form::idealB;
duke@0 276 if( strcmp(opType,"StoreC")==0) return Form::idealC;
duke@0 277 if( strcmp(opType,"StoreD")==0) return Form::idealD;
duke@0 278 if( strcmp(opType,"StoreF")==0) return Form::idealF;
duke@0 279 if( strcmp(opType,"StoreI")==0) return Form::idealI;
duke@0 280 if( strcmp(opType,"StoreL")==0) return Form::idealL;
duke@0 281 if( strcmp(opType,"StoreP")==0) return Form::idealP;
kvn@3447 282 if( strcmp(opType,"StoreN")==0) return Form::idealN;
roland@3724 283 if( strcmp(opType,"StoreNKlass")==0) return Form::idealNKlass;
kvn@3447 284 if( strcmp(opType,"StoreVector")==0 ) return Form::idealV;
duke@0 285 assert( strcmp(opType,"Store") != 0, "Must type Stores" );
duke@0 286 return Form::none;
duke@0 287 }
duke@0 288
duke@0 289 Form::InterfaceType Form::interface_type(FormDict &globals) const {
duke@0 290 return Form::no_interface;
duke@0 291 }
duke@0 292
duke@0 293 //------------------------------FormList---------------------------------------
duke@0 294 // Destructor
duke@0 295 FormList::~FormList() {
duke@0 296 // // This list may not own its elements
duke@0 297 // Form *cur = _root;
duke@0 298 // Form *next = NULL;
duke@0 299 // for( ; (cur = next) != NULL; ) {
duke@0 300 // next = (Form *)cur->_next;
duke@0 301 // delete cur;
duke@0 302 // }
duke@0 303 };
duke@0 304
duke@0 305 //------------------------------FormDict---------------------------------------
duke@0 306 // Constructor
duke@0 307 FormDict::FormDict( CmpKey cmp, Hash hash, Arena *arena )
duke@0 308 : _form(cmp, hash, arena) {
duke@0 309 }
duke@0 310 FormDict::~FormDict() {
duke@0 311 }
duke@0 312
duke@0 313 // Return # of name-Form pairs in dict
duke@0 314 int FormDict::Size(void) const {
duke@0 315 return _form.Size();
duke@0 316 }
duke@0 317
duke@0 318 // Insert inserts the given key-value pair into the dictionary. The prior
duke@0 319 // value of the key is returned; NULL if the key was not previously defined.
duke@0 320 const Form *FormDict::Insert(const char *name, Form *form) {
duke@0 321 return (Form*)_form.Insert((void*)name, (void*)form);
duke@0 322 }
duke@0 323
duke@0 324 // Finds the value of a given key; or NULL if not found.
duke@0 325 // The dictionary is NOT changed.
duke@0 326 const Form *FormDict::operator [](const char *name) const {
duke@0 327 return (Form*)_form[name];
duke@0 328 }
duke@0 329
duke@0 330 //------------------------------FormDict::private------------------------------
duke@0 331 // Disable public use of constructor, copy-ctor, operator =, operator ==
duke@0 332 FormDict::FormDict( ) : _form(cmpkey,hashkey) {
duke@0 333 assert( false, "NotImplemented");
duke@0 334 }
duke@0 335 FormDict::FormDict( const FormDict & fd) : _form(fd._form) {
duke@0 336 }
duke@0 337 FormDict &FormDict::operator =( const FormDict &rhs) {
duke@0 338 assert( false, "NotImplemented");
duke@0 339 _form = rhs._form;
duke@0 340 return *this;
duke@0 341 }
duke@0 342 // == compares two dictionaries; they must have the same keys (their keys
duke@0 343 // must match using CmpKey) and they must have the same values (pointer
duke@0 344 // comparison). If so 1 is returned, if not 0 is returned.
duke@0 345 bool FormDict::operator ==(const FormDict &d) const {
duke@0 346 assert( false, "NotImplemented");
duke@0 347 return false;
duke@0 348 }
duke@0 349
duke@0 350 // Print out the dictionary contents as key-value pairs
twisti@603 351 static void dumpkey (const void* key) { fprintf(stdout, "%s", (char*) key); }
duke@0 352 static void dumpform(const void* form) { fflush(stdout); ((Form*)form)->dump(); }
duke@0 353
duke@0 354 void FormDict::dump() {
duke@0 355 _form.print(dumpkey, dumpform);
duke@0 356 }
duke@0 357
duke@0 358 //------------------------------SourceForm-------------------------------------
duke@0 359 SourceForm::SourceForm(char* code) : _code(code) { }; // Constructor
duke@0 360 SourceForm::~SourceForm() {
duke@0 361 }
duke@0 362
duke@0 363 void SourceForm::dump() { // Debug printer
duke@0 364 output(stderr);
duke@0 365 }
duke@0 366
duke@0 367 void SourceForm::output(FILE *fp) {
duke@0 368 fprintf(fp,"\n//%s\n%s\n",classname(),(_code?_code:""));
duke@0 369 }