351 if (is_osr_compilation()) {
352 tty->print("[OSR]%3d", _compile_id);
353 } else {
354 tty->print("%3d", _compile_id);
355 }
356 }
357 #endif
358 }
359
360
361 void Compile::init_scratch_buffer_blob() {
362 if( scratch_buffer_blob() != NULL ) return;
363
364 // Construct a temporary CodeBuffer to have it construct a BufferBlob
365 // Cache this BufferBlob for this compile.
366 ResourceMark rm;
367 int size = (MAX_inst_size + MAX_stubs_size + MAX_const_size);
368 BufferBlob* blob = BufferBlob::create("Compile::scratch_buffer", size);
369 // Record the buffer blob for next time.
370 set_scratch_buffer_blob(blob);
371 guarantee(scratch_buffer_blob() != NULL, "Need BufferBlob for code generation");
372
373 // Initialize the relocation buffers
374 relocInfo* locs_buf = (relocInfo*) blob->instructions_end() - MAX_locs_size;
375 set_scratch_locs_memory(locs_buf);
376 }
377
378
379 //-----------------------scratch_emit_size-------------------------------------
380 // Helper function that computes size by emitting code
381 uint Compile::scratch_emit_size(const Node* n) {
382 // Emit into a trash buffer and count bytes emitted.
383 // This is a pretty expensive way to compute a size,
384 // but it works well enough if seldom used.
385 // All common fixed-size instructions are given a size
386 // method by the AD file.
387 // Note that the scratch buffer blob and locs memory are
388 // allocated at the beginning of the compile task, and
389 // may be shared by several calls to scratch_emit_size.
390 // The allocation of the scratch buffer blob is particularly
391 // expensive, since it has to grab the code cache lock.
1048 }
1049 // During the 2nd round of IterGVN, NotNull castings are removed.
1050 // Make sure the Bottom and NotNull variants alias the same.
1051 // Also, make sure exact and non-exact variants alias the same.
1052 if( ptr == TypePtr::NotNull || ta->klass_is_exact() ) {
1053 if (ta->const_oop()) {
1054 tj = ta = TypeAryPtr::make(TypePtr::Constant,ta->const_oop(),ta->ary(),ta->klass(),false,offset);
1055 } else {
1056 tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset);
1057 }
1058 }
1059 }
1060
1061 // Oop pointers need some flattening
1062 const TypeInstPtr *to = tj->isa_instptr();
1063 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1064 if( ptr == TypePtr::Constant ) {
1065 // No constant oop pointers (such as Strings); they alias with
1066 // unknown strings.
1067 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1068 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1069 // During the 2nd round of IterGVN, NotNull castings are removed.
1070 // Make sure the Bottom and NotNull variants alias the same.
1071 // Also, make sure exact and non-exact variants alias the same.
1072 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset, to->instance_id());
1073 }
1074 // Canonicalize the holder of this field
1075 ciInstanceKlass *k = to->klass()->as_instance_klass();
1076 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1077 // First handle header references such as a LoadKlassNode, even if the
1078 // object's klass is unloaded at compile time (4965979).
1079 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset, to->instance_id());
1080 } else if (offset < 0 || offset >= k->size_helper() * wordSize) {
1081 to = NULL;
1082 tj = TypeOopPtr::BOTTOM;
1083 offset = tj->offset();
1084 } else {
1085 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
1086 if (!k->equals(canonical_holder) || tj->offset() != offset) {
1087 tj = to = TypeInstPtr::make(TypePtr::BotPTR, canonical_holder, false, NULL, offset, to->instance_id());
1088 }
1089 }
1090 }
1091
1092 // Klass pointers to object array klasses need some flattening
1093 const TypeKlassPtr *tk = tj->isa_klassptr();
1094 if( tk ) {
1095 // If we are referencing a field within a Klass, we need
1096 // to assume the worst case of an Object. Both exact and
1097 // inexact types must flatten to the same alias class.
1098 // Since the flattened result for a klass is defined to be
1099 // precisely java.lang.Object, use a constant ptr.
1100 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1101
1102 tj = tk = TypeKlassPtr::make(TypePtr::Constant,
1103 TypeKlassPtr::OBJECT->klass(),
1104 offset);
1105 }
1106
1107 ciKlass* klass = tk->klass();
|
351 if (is_osr_compilation()) {
352 tty->print("[OSR]%3d", _compile_id);
353 } else {
354 tty->print("%3d", _compile_id);
355 }
356 }
357 #endif
358 }
359
360
361 void Compile::init_scratch_buffer_blob() {
362 if( scratch_buffer_blob() != NULL ) return;
363
364 // Construct a temporary CodeBuffer to have it construct a BufferBlob
365 // Cache this BufferBlob for this compile.
366 ResourceMark rm;
367 int size = (MAX_inst_size + MAX_stubs_size + MAX_const_size);
368 BufferBlob* blob = BufferBlob::create("Compile::scratch_buffer", size);
369 // Record the buffer blob for next time.
370 set_scratch_buffer_blob(blob);
371 // Have we run out of code space?
372 if (scratch_buffer_blob() == NULL) {
373 // Let CompilerBroker disable further compilations.
374 record_failure("Not enough space for scratch buffer in CodeCache");
375 return;
376 }
377
378 // Initialize the relocation buffers
379 relocInfo* locs_buf = (relocInfo*) blob->instructions_end() - MAX_locs_size;
380 set_scratch_locs_memory(locs_buf);
381 }
382
383
384 //-----------------------scratch_emit_size-------------------------------------
385 // Helper function that computes size by emitting code
386 uint Compile::scratch_emit_size(const Node* n) {
387 // Emit into a trash buffer and count bytes emitted.
388 // This is a pretty expensive way to compute a size,
389 // but it works well enough if seldom used.
390 // All common fixed-size instructions are given a size
391 // method by the AD file.
392 // Note that the scratch buffer blob and locs memory are
393 // allocated at the beginning of the compile task, and
394 // may be shared by several calls to scratch_emit_size.
395 // The allocation of the scratch buffer blob is particularly
396 // expensive, since it has to grab the code cache lock.
1053 }
1054 // During the 2nd round of IterGVN, NotNull castings are removed.
1055 // Make sure the Bottom and NotNull variants alias the same.
1056 // Also, make sure exact and non-exact variants alias the same.
1057 if( ptr == TypePtr::NotNull || ta->klass_is_exact() ) {
1058 if (ta->const_oop()) {
1059 tj = ta = TypeAryPtr::make(TypePtr::Constant,ta->const_oop(),ta->ary(),ta->klass(),false,offset);
1060 } else {
1061 tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset);
1062 }
1063 }
1064 }
1065
1066 // Oop pointers need some flattening
1067 const TypeInstPtr *to = tj->isa_instptr();
1068 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1069 if( ptr == TypePtr::Constant ) {
1070 // No constant oop pointers (such as Strings); they alias with
1071 // unknown strings.
1072 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1073 } else if( to->is_instance_field() ) {
1074 tj = to; // Keep NotNull and klass_is_exact for instance type
1075 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1076 // During the 2nd round of IterGVN, NotNull castings are removed.
1077 // Make sure the Bottom and NotNull variants alias the same.
1078 // Also, make sure exact and non-exact variants alias the same.
1079 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset, to->instance_id());
1080 }
1081 // Canonicalize the holder of this field
1082 ciInstanceKlass *k = to->klass()->as_instance_klass();
1083 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
1084 // First handle header references such as a LoadKlassNode, even if the
1085 // object's klass is unloaded at compile time (4965979).
1086 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset, to->instance_id());
1087 } else if (offset < 0 || offset >= k->size_helper() * wordSize) {
1088 to = NULL;
1089 tj = TypeOopPtr::BOTTOM;
1090 offset = tj->offset();
1091 } else {
1092 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
1093 if (!k->equals(canonical_holder) || tj->offset() != offset) {
1094 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset, to->instance_id());
1095 }
1096 }
1097 }
1098
1099 // Klass pointers to object array klasses need some flattening
1100 const TypeKlassPtr *tk = tj->isa_klassptr();
1101 if( tk ) {
1102 // If we are referencing a field within a Klass, we need
1103 // to assume the worst case of an Object. Both exact and
1104 // inexact types must flatten to the same alias class.
1105 // Since the flattened result for a klass is defined to be
1106 // precisely java.lang.Object, use a constant ptr.
1107 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1108
1109 tj = tk = TypeKlassPtr::make(TypePtr::Constant,
1110 TypeKlassPtr::OBJECT->klass(),
1111 offset);
1112 }
1113
1114 ciKlass* klass = tk->klass();
|