Mercurial > hg > graal-jvmci-8
comparison src/share/vm/adlc/output_c.cpp @ 9078:705ef39fcaa9
8006016: Memory leak at hotspot/src/share/vm/adlc/output_c.cpp
Reviewed-by: kvn, roland
Contributed-by: niclas.adlertz@oracle.com
author | neliasso |
---|---|
date | Fri, 05 Apr 2013 11:09:43 +0200 |
parents | d336b3173277 |
children | f15fe46d8c00 |
comparison
equal
deleted
inserted
replaced
9055:dcdeb150988c | 9078:705ef39fcaa9 |
---|---|
61 | 61 |
62 // Output the register name for each register in the allocation classes | 62 // Output the register name for each register in the allocation classes |
63 RegDef *reg_def = NULL; | 63 RegDef *reg_def = NULL; |
64 RegDef *next = NULL; | 64 RegDef *next = NULL; |
65 registers->reset_RegDefs(); | 65 registers->reset_RegDefs(); |
66 for( reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next ) { | 66 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) { |
67 next = registers->iter_RegDefs(); | 67 next = registers->iter_RegDefs(); |
68 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | 68 const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
69 fprintf(fp," \"%s\"%s\n", | 69 fprintf(fp," \"%s\"%s\n", reg_def->_regname, comma); |
70 reg_def->_regname, comma ); | |
71 } | 70 } |
72 | 71 |
73 // Finish defining enumeration | 72 // Finish defining enumeration |
74 fprintf(fp,"};\n"); | 73 fprintf(fp,"};\n"); |
75 | 74 |
77 fprintf(fp,"// An array of character pointers to machine register names.\n"); | 76 fprintf(fp,"// An array of character pointers to machine register names.\n"); |
78 fprintf(fp,"const VMReg OptoReg::opto2vm[REG_COUNT] = {\n"); | 77 fprintf(fp,"const VMReg OptoReg::opto2vm[REG_COUNT] = {\n"); |
79 reg_def = NULL; | 78 reg_def = NULL; |
80 next = NULL; | 79 next = NULL; |
81 registers->reset_RegDefs(); | 80 registers->reset_RegDefs(); |
82 for( reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next ) { | 81 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) { |
83 next = registers->iter_RegDefs(); | 82 next = registers->iter_RegDefs(); |
84 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | 83 const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
85 fprintf(fp,"\t%s%s\n", reg_def->_concrete, comma ); | 84 fprintf(fp,"\t%s%s\n", reg_def->_concrete, comma); |
86 } | 85 } |
87 // Finish defining array | 86 // Finish defining array |
88 fprintf(fp,"\t};\n"); | 87 fprintf(fp,"\t};\n"); |
89 fprintf(fp,"\n"); | 88 fprintf(fp,"\n"); |
90 | 89 |
102 | 101 |
103 // Output the register encoding for each register in the allocation classes | 102 // Output the register encoding for each register in the allocation classes |
104 RegDef *reg_def = NULL; | 103 RegDef *reg_def = NULL; |
105 RegDef *next = NULL; | 104 RegDef *next = NULL; |
106 registers->reset_RegDefs(); | 105 registers->reset_RegDefs(); |
107 for( reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next ) { | 106 for (reg_def = registers->iter_RegDefs(); reg_def != NULL; reg_def = next) { |
108 next = registers->iter_RegDefs(); | 107 next = registers->iter_RegDefs(); |
109 const char* register_encode = reg_def->register_encode(); | 108 const char* register_encode = reg_def->register_encode(); |
110 const char *comma = (next != NULL) ? "," : " // no trailing comma"; | 109 const char *comma = (next != NULL) ? "," : " // no trailing comma"; |
111 int encval; | 110 int encval; |
112 if (!ADLParser::is_int_token(register_encode, encval)) { | 111 if (!ADLParser::is_int_token(register_encode, encval)) { |
113 fprintf(fp," %s%s // %s\n", | 112 fprintf(fp," %s%s // %s\n", register_encode, comma, reg_def->_regname); |
114 register_encode, comma, reg_def->_regname ); | |
115 } else { | 113 } else { |
116 // Output known constants in hex char format (backward compatibility). | 114 // Output known constants in hex char format (backward compatibility). |
117 assert(encval < 256, "Exceeded supported width for register encoding"); | 115 assert(encval < 256, "Exceeded supported width for register encoding"); |
118 fprintf(fp," (unsigned char)'\\x%X'%s // %s\n", | 116 fprintf(fp," (unsigned char)'\\x%X'%s // %s\n", encval, comma, reg_def->_regname); |
119 encval, comma, reg_def->_regname ); | |
120 } | 117 } |
121 } | 118 } |
122 // Finish defining enumeration | 119 // Finish defining enumeration |
123 fprintf(fp,"};\n"); | 120 fprintf(fp,"};\n"); |
124 | 121 |
131 // Output an enumeration of register class names | 128 // Output an enumeration of register class names |
132 fprintf(fp,"\n"); | 129 fprintf(fp,"\n"); |
133 fprintf(fp,"// Enumeration of register class names\n"); | 130 fprintf(fp,"// Enumeration of register class names\n"); |
134 fprintf(fp, "enum machRegisterClass {\n"); | 131 fprintf(fp, "enum machRegisterClass {\n"); |
135 registers->_rclasses.reset(); | 132 registers->_rclasses.reset(); |
136 for( const char *class_name = NULL; | 133 for (const char *class_name = NULL; (class_name = registers->_rclasses.iter()) != NULL;) { |
137 (class_name = registers->_rclasses.iter()) != NULL; ) { | 134 const char * class_name_to_upper = toUpper(class_name); |
138 fprintf(fp," %s,\n", toUpper( class_name )); | 135 fprintf(fp," %s,\n", class_name_to_upper); |
136 delete[] class_name_to_upper; | |
139 } | 137 } |
140 // Finish defining enumeration | 138 // Finish defining enumeration |
141 fprintf(fp, " _last_Mach_Reg_Class\n"); | 139 fprintf(fp, " _last_Mach_Reg_Class\n"); |
142 fprintf(fp, "};\n"); | 140 fprintf(fp, "};\n"); |
143 } | 141 } |
146 // Declare an enumeration of user-defined register classes | 144 // Declare an enumeration of user-defined register classes |
147 // and a list of register masks, one for each class. | 145 // and a list of register masks, one for each class. |
148 void ArchDesc::declare_register_masks(FILE *fp_hpp) { | 146 void ArchDesc::declare_register_masks(FILE *fp_hpp) { |
149 const char *rc_name; | 147 const char *rc_name; |
150 | 148 |
151 if( _register ) { | 149 if (_register) { |
152 // Build enumeration of user-defined register classes. | 150 // Build enumeration of user-defined register classes. |
153 defineRegClassEnum(fp_hpp, _register); | 151 defineRegClassEnum(fp_hpp, _register); |
154 | 152 |
155 // Generate a list of register masks, one for each class. | 153 // Generate a list of register masks, one for each class. |
156 fprintf(fp_hpp,"\n"); | 154 fprintf(fp_hpp,"\n"); |
157 fprintf(fp_hpp,"// Register masks, one for each register class.\n"); | 155 fprintf(fp_hpp,"// Register masks, one for each register class.\n"); |
158 _register->_rclasses.reset(); | 156 _register->_rclasses.reset(); |
159 for( rc_name = NULL; | 157 for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) { |
160 (rc_name = _register->_rclasses.iter()) != NULL; ) { | 158 const char *prefix = ""; |
161 const char *prefix = ""; | 159 RegClass *reg_class = _register->getRegClass(rc_name); |
162 RegClass *reg_class = _register->getRegClass(rc_name); | 160 assert(reg_class, "Using an undefined register class"); |
163 assert( reg_class, "Using an undefined register class"); | 161 |
162 const char* rc_name_to_upper = toUpper(rc_name); | |
164 | 163 |
165 if (reg_class->_user_defined == NULL) { | 164 if (reg_class->_user_defined == NULL) { |
166 fprintf(fp_hpp, "extern const RegMask _%s%s_mask;\n", prefix, toUpper( rc_name ) ); | 165 fprintf(fp_hpp, "extern const RegMask _%s%s_mask;\n", prefix, rc_name_to_upper); |
167 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { return _%s%s_mask; }\n", prefix, toUpper( rc_name ), prefix, toUpper( rc_name )); | 166 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { return _%s%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper); |
168 } else { | 167 } else { |
169 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { %s }\n", prefix, toUpper( rc_name ), reg_class->_user_defined); | 168 fprintf(fp_hpp, "inline const RegMask &%s%s_mask() { %s }\n", prefix, rc_name_to_upper, reg_class->_user_defined); |
170 } | 169 } |
171 | 170 |
172 if( reg_class->_stack_or_reg ) { | 171 if (reg_class->_stack_or_reg) { |
173 assert(reg_class->_user_defined == NULL, "no user defined reg class here"); | 172 assert(reg_class->_user_defined == NULL, "no user defined reg class here"); |
174 fprintf(fp_hpp, "extern const RegMask _%sSTACK_OR_%s_mask;\n", prefix, toUpper( rc_name ) ); | 173 fprintf(fp_hpp, "extern const RegMask _%sSTACK_OR_%s_mask;\n", prefix, rc_name_to_upper); |
175 fprintf(fp_hpp, "inline const RegMask &%sSTACK_OR_%s_mask() { return _%sSTACK_OR_%s_mask; }\n", prefix, toUpper( rc_name ), prefix, toUpper( rc_name ) ); | 174 fprintf(fp_hpp, "inline const RegMask &%sSTACK_OR_%s_mask() { return _%sSTACK_OR_%s_mask; }\n", prefix, rc_name_to_upper, prefix, rc_name_to_upper); |
176 } | 175 } |
176 delete[] rc_name_to_upper; | |
177 | |
177 } | 178 } |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 // Generate an enumeration of user-defined register classes | 182 // Generate an enumeration of user-defined register classes |
182 // and a list of register masks, one for each class. | 183 // and a list of register masks, one for each class. |
183 void ArchDesc::build_register_masks(FILE *fp_cpp) { | 184 void ArchDesc::build_register_masks(FILE *fp_cpp) { |
184 const char *rc_name; | 185 const char *rc_name; |
185 | 186 |
186 if( _register ) { | 187 if (_register) { |
187 // Generate a list of register masks, one for each class. | 188 // Generate a list of register masks, one for each class. |
188 fprintf(fp_cpp,"\n"); | 189 fprintf(fp_cpp,"\n"); |
189 fprintf(fp_cpp,"// Register masks, one for each register class.\n"); | 190 fprintf(fp_cpp,"// Register masks, one for each register class.\n"); |
190 _register->_rclasses.reset(); | 191 _register->_rclasses.reset(); |
191 for( rc_name = NULL; | 192 for (rc_name = NULL; (rc_name = _register->_rclasses.iter()) != NULL;) { |
192 (rc_name = _register->_rclasses.iter()) != NULL; ) { | 193 const char *prefix = ""; |
193 const char *prefix = ""; | 194 RegClass *reg_class = _register->getRegClass(rc_name); |
194 RegClass *reg_class = _register->getRegClass(rc_name); | 195 assert(reg_class, "Using an undefined register class"); |
195 assert( reg_class, "Using an undefined register class"); | 196 |
196 | 197 if (reg_class->_user_defined != NULL) { |
197 if (reg_class->_user_defined != NULL) continue; | 198 continue; |
199 } | |
198 | 200 |
199 int len = RegisterForm::RegMask_Size(); | 201 int len = RegisterForm::RegMask_Size(); |
200 fprintf(fp_cpp, "const RegMask _%s%s_mask(", prefix, toUpper( rc_name ) ); | 202 const char* rc_name_to_upper = toUpper(rc_name); |
201 { int i; | 203 fprintf(fp_cpp, "const RegMask _%s%s_mask(", prefix, rc_name_to_upper); |
202 for( i = 0; i < len-1; i++ ) | 204 |
203 fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i,false)); | 205 { |
204 fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i,false)); | |
205 } | |
206 | |
207 if( reg_class->_stack_or_reg ) { | |
208 int i; | 206 int i; |
209 fprintf(fp_cpp, "const RegMask _%sSTACK_OR_%s_mask(", prefix, toUpper( rc_name ) ); | 207 for(i = 0; i < len - 1; i++) { |
210 for( i = 0; i < len-1; i++ ) | 208 fprintf(fp_cpp," 0x%x,", reg_class->regs_in_word(i, false)); |
211 fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i,true)); | 209 } |
212 fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i,true)); | 210 fprintf(fp_cpp," 0x%x );\n", reg_class->regs_in_word(i, false)); |
213 } | 211 } |
212 | |
213 if (reg_class->_stack_or_reg) { | |
214 int i; | |
215 fprintf(fp_cpp, "const RegMask _%sSTACK_OR_%s_mask(", prefix, rc_name_to_upper); | |
216 for(i = 0; i < len - 1; i++) { | |
217 fprintf(fp_cpp," 0x%x,",reg_class->regs_in_word(i, true)); | |
218 } | |
219 fprintf(fp_cpp," 0x%x );\n",reg_class->regs_in_word(i, true)); | |
220 } | |
221 delete[] rc_name_to_upper; | |
214 } | 222 } |
215 } | 223 } |
216 } | 224 } |
217 | 225 |
218 // Compute an index for an array in the pipeline_reads_NNN arrays | 226 // Compute an index for an array in the pipeline_reads_NNN arrays |
2674 if (all_same) { | 2682 if (all_same) { |
2675 // Return the sole RegMask. | 2683 // Return the sole RegMask. |
2676 if (strcmp(first_reg_class, "stack_slots") == 0) { | 2684 if (strcmp(first_reg_class, "stack_slots") == 0) { |
2677 fprintf(fp," return &(Compile::current()->FIRST_STACK_mask());\n"); | 2685 fprintf(fp," return &(Compile::current()->FIRST_STACK_mask());\n"); |
2678 } else { | 2686 } else { |
2679 fprintf(fp," return &%s_mask();\n", toUpper(first_reg_class)); | 2687 const char* first_reg_class_to_upper = toUpper(first_reg_class); |
2688 fprintf(fp," return &%s_mask();\n", first_reg_class_to_upper); | |
2689 delete[] first_reg_class_to_upper; | |
2680 } | 2690 } |
2681 } else { | 2691 } else { |
2682 // Build a switch statement to return the desired mask. | 2692 // Build a switch statement to return the desired mask. |
2683 fprintf(fp," switch (index) {\n"); | 2693 fprintf(fp," switch (index) {\n"); |
2684 | 2694 |
2686 const char *reg_class = oper.in_reg_class(index, globals); | 2696 const char *reg_class = oper.in_reg_class(index, globals); |
2687 assert(reg_class != NULL, "did not find register mask"); | 2697 assert(reg_class != NULL, "did not find register mask"); |
2688 if( !strcmp(reg_class, "stack_slots") ) { | 2698 if( !strcmp(reg_class, "stack_slots") ) { |
2689 fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index); | 2699 fprintf(fp, " case %d: return &(Compile::current()->FIRST_STACK_mask());\n", index); |
2690 } else { | 2700 } else { |
2691 fprintf(fp, " case %d: return &%s_mask();\n", index, toUpper(reg_class)); | 2701 const char* reg_class_to_upper = toUpper(reg_class); |
2702 fprintf(fp, " case %d: return &%s_mask();\n", index, reg_class_to_upper); | |
2703 delete[] reg_class_to_upper; | |
2692 } | 2704 } |
2693 } | 2705 } |
2694 fprintf(fp," }\n"); | 2706 fprintf(fp," }\n"); |
2695 fprintf(fp," ShouldNotReachHere();\n"); | 2707 fprintf(fp," ShouldNotReachHere();\n"); |
2696 fprintf(fp," return NULL;\n"); | 2708 fprintf(fp," return NULL;\n"); |