comparison src/share/vm/adlc/dfa.cpp @ 8878:573cf206e381

8006014: Memory leak in hotspot/src/share/vm/adlc/dfa.cpp Reviewed-by: kvn, roland Contributed-by: niclas.adlertz@oracle.com
author neliasso
date Thu, 04 Apr 2013 09:30:06 +0200
parents f95d63e2154a
children de6a9e811145
comparison
equal deleted inserted replaced
8877:9125a548c1eb 8878:573cf206e381
189 // Example: 189 // Example:
190 // STATE__VALID_CHILD(_kids[0], FOO) && STATE__VALID_CHILD(_kids[1], BAR) 190 // STATE__VALID_CHILD(_kids[0], FOO) && STATE__VALID_CHILD(_kids[1], BAR)
191 // Macro equivalent to: _kids[0]->valid(FOO) && _kids[1]->valid(BAR) 191 // Macro equivalent to: _kids[0]->valid(FOO) && _kids[1]->valid(BAR)
192 // 192 //
193 static void child_test(FILE *fp, MatchList &mList) { 193 static void child_test(FILE *fp, MatchList &mList) {
194 if( mList._lchild ) // If left child, check it 194 if (mList._lchild) { // If left child, check it
195 fprintf(fp, "STATE__VALID_CHILD(_kids[0], %s)", ArchDesc::getMachOperEnum(mList._lchild)); 195 const char* lchild_to_upper = ArchDesc::getMachOperEnum(mList._lchild);
196 if( mList._lchild && mList._rchild ) // If both, add the "&&" 196 fprintf(fp, "STATE__VALID_CHILD(_kids[0], %s)", lchild_to_upper);
197 fprintf(fp, " && " ); 197 delete[] lchild_to_upper;
198 if( mList._rchild ) // If right child, check it 198 }
199 fprintf(fp, "STATE__VALID_CHILD(_kids[1], %s)", ArchDesc::getMachOperEnum(mList._rchild)); 199 if (mList._lchild && mList._rchild) { // If both, add the "&&"
200 fprintf(fp, " && ");
201 }
202 if (mList._rchild) { // If right child, check it
203 const char* rchild_to_upper = ArchDesc::getMachOperEnum(mList._rchild);
204 fprintf(fp, "STATE__VALID_CHILD(_kids[1], %s)", rchild_to_upper);
205 delete[] rchild_to_upper;
206 }
200 } 207 }
201 208
202 //---------------------------calc_cost----------------------------------------- 209 //---------------------------calc_cost-----------------------------------------
203 // Example: 210 // Example:
204 // unsigned int c = _kids[0]->_cost[FOO] + _kids[1]->_cost[BAR] + 5; 211 // unsigned int c = _kids[0]->_cost[FOO] + _kids[1]->_cost[BAR] + 5;
205 // 212 //
206 Expr *ArchDesc::calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status) { 213 Expr *ArchDesc::calc_cost(FILE *fp, const char *spaces, MatchList &mList, ProductionState &status) {
207 fprintf(fp, "%sunsigned int c = ", spaces); 214 fprintf(fp, "%sunsigned int c = ", spaces);
208 Expr *c = new Expr("0"); 215 Expr *c = new Expr("0");
209 if (mList._lchild ) { // If left child, add it in 216 if (mList._lchild) { // If left child, add it in
210 sprintf(Expr::buffer(), "_kids[0]->_cost[%s]", ArchDesc::getMachOperEnum(mList._lchild)); 217 const char* lchild_to_upper = ArchDesc::getMachOperEnum(mList._lchild);
218 sprintf(Expr::buffer(), "_kids[0]->_cost[%s]", lchild_to_upper);
211 c->add(Expr::buffer()); 219 c->add(Expr::buffer());
212 } 220 delete[] lchild_to_upper;
213 if (mList._rchild) { // If right child, add it in 221 }
214 sprintf(Expr::buffer(), "_kids[1]->_cost[%s]", ArchDesc::getMachOperEnum(mList._rchild)); 222 if (mList._rchild) { // If right child, add it in
223 const char* rchild_to_upper = ArchDesc::getMachOperEnum(mList._rchild);
224 sprintf(Expr::buffer(), "_kids[1]->_cost[%s]", rchild_to_upper);
215 c->add(Expr::buffer()); 225 c->add(Expr::buffer());
226 delete[] rchild_to_upper;
216 } 227 }
217 // Add in cost of this rule 228 // Add in cost of this rule
218 const char *mList_cost = mList.get_cost(); 229 const char *mList_cost = mList.get_cost();
219 c->add(mList_cost, *this); 230 c->add(mList_cost, *this);
220 231
230 const char *spaces6 = " "; 241 const char *spaces6 = " ";
231 242
232 fprintf(fp, "%s", spaces4); 243 fprintf(fp, "%s", spaces4);
233 // Only generate child tests if this is not a leaf node 244 // Only generate child tests if this is not a leaf node
234 bool has_child_constraints = mList._lchild || mList._rchild; 245 bool has_child_constraints = mList._lchild || mList._rchild;
235 const char *predicate_test = mList.get_pred(); 246 const char *predicate_test = mList.get_pred();
236 if( has_child_constraints || predicate_test ) { 247 if (has_child_constraints || predicate_test) {
237 // Open the child-and-predicate-test braces 248 // Open the child-and-predicate-test braces
238 fprintf(fp, "if( "); 249 fprintf(fp, "if( ");
239 status.set_constraint(hasConstraint); 250 status.set_constraint(hasConstraint);
240 child_test(fp, mList); 251 child_test(fp, mList);
241 // Only generate predicate test if one exists for this match 252 // Only generate predicate test if one exists for this match
242 if( predicate_test ) { 253 if (predicate_test) {
243 if( has_child_constraints ) { fprintf(fp," &&\n"); } 254 if (has_child_constraints) {
255 fprintf(fp," &&\n");
256 }
244 fprintf(fp, "%s %s", spaces6, predicate_test); 257 fprintf(fp, "%s %s", spaces6, predicate_test);
245 } 258 }
246 // End of outer tests 259 // End of outer tests
247 fprintf(fp," ) "); 260 fprintf(fp," ) ");
248 } else { 261 } else {