void ThreadLocalAllocBuffer::resize() { // Compute the next tlab size using expected allocation amount assert(ResizeTLAB, "Should not call this otherwise"); size_t alloc = (size_t)(_allocation_fraction.average() * (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize)); size_t new_size = alloc / _target_refills; new_size = MIN2(MAX2(new_size, min_size()), max_size()); size_t aligned_new_size = align_object_size(new_size); if (PrintTLAB && Verbose) { gclog_or_tty->print("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]" " refills %d alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT "\n", p2i(myThread()), myThread()->osthread()->thread_id(), _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size); } set_desired_size(aligned_new_size); set_refill_waste_limit(initial_refill_waste_limit()); }
// The rate estimate is in blocks per second. void compute_desired(size_t count, float inter_sweep_current, float inter_sweep_estimate, float intra_sweep_estimate) { // If the latest inter-sweep time is below our granularity // of measurement, we may call in here with // inter_sweep_current == 0. However, even for suitably small // but non-zero inter-sweep durations, we may not trust the accuracy // of accumulated data, since it has not been "integrated" // (read "low-pass-filtered") long enough, and would be // vulnerable to noisy glitches. In such cases, we // ignore the current sample and use currently available // historical estimates. assert(prev_sweep() + split_births() + coal_births() // "Total Production Stock" >= split_deaths() + coal_deaths() + (ssize_t)count, // "Current stock + depletion" "Conservation Principle"); if (inter_sweep_current > _threshold) { ssize_t demand = prev_sweep() - (ssize_t)count + split_births() + coal_births() - split_deaths() - coal_deaths(); assert(demand >= 0, err_msg("Demand (" SSIZE_FORMAT ") should be non-negative for " PTR_FORMAT " (size=" SIZE_FORMAT ")", demand, p2i(this), count)); // Defensive: adjust for imprecision in event counting if (demand < 0) { demand = 0; } float old_rate = _demand_rate_estimate.padded_average(); float rate = ((float)demand)/inter_sweep_current; _demand_rate_estimate.sample(rate); float new_rate = _demand_rate_estimate.padded_average(); ssize_t old_desired = _desired; float delta_ise = (CMSExtrapolateSweep ? intra_sweep_estimate : 0.0); _desired = (ssize_t)(new_rate * (inter_sweep_estimate + delta_ise)); if (PrintFLSStatistics > 1) { gclog_or_tty->print_cr("demand: " SSIZE_FORMAT ", old_rate: %f, current_rate: %f, " "new_rate: %f, old_desired: " SSIZE_FORMAT ", new_desired: " SSIZE_FORMAT, demand, old_rate, rate, new_rate, old_desired, _desired); } } }
// Walk the next batch of stack frames // // Parameters: // stackStream StackStream object // mode Stack walking mode. // magic Must be valid value to continue the stack walk // frame_count Number of frames to be decoded. // start_index Start index to the user-supplied buffers. // frames_array Buffer to store StackFrame in, starting at start_index. // // Returns the end index of frame filled in the buffer. // jint StackWalk::moreFrames(Handle stackStream, jlong mode, jlong magic, int frame_count, int start_index, objArrayHandle frames_array, TRAPS) { JavaThread* jt = (JavaThread*)THREAD; JavaFrameStream* existing_stream = JavaFrameStream::from_current(jt, magic, frames_array); if (existing_stream == NULL) { THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers", 0L); } if (frames_array.is_null()) { THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", 0L); } if (TraceStackWalk) { tty->print_cr("StackWalk::moreFrames frame_count %d existing_stream " PTR_FORMAT " start %d frames %d", frame_count, p2i(existing_stream), start_index, frames_array->length()); } int end_index = start_index; if (frame_count <= 0) { return end_index; // No operation. } int count = frame_count + start_index; assert (frames_array->length() >= count, "not enough space in buffers"); JavaFrameStream& stream = (*existing_stream); if (!stream.at_end()) { stream.next(); // advance past the last frame decoded in previous batch if (!stream.at_end()) { int n = fill_in_frames(mode, stream, frame_count, start_index, frames_array, end_index, CHECK_0); if (n < 1) { THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: later decode failed", 0L); } return end_index; } } return end_index; }
size_t ContiguousSpace::block_size(const HeapWord* p) const { assert(MemRegion(bottom(), end()).contains(p), "p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")", p2i(p), p2i(bottom()), p2i(end())); HeapWord* current_top = top(); assert(p <= current_top, "p > current top - p: " PTR_FORMAT ", current top: " PTR_FORMAT, p2i(p), p2i(current_top)); assert(p == current_top || oop(p)->is_oop(), "p (" PTR_FORMAT ") is not a block start - " "current_top: " PTR_FORMAT ", is_oop: %s", p2i(p), p2i(current_top), BOOL_TO_STR(oop(p)->is_oop())); if (p < current_top) { return oop(p)->size(); } else { assert(p == current_top, "just checking"); return pointer_delta(end(), (HeapWord*) p); } }
void HeapRegionManager::verify() { guarantee(length() <= _allocated_heapregions_length, "invariant: _length: %u _allocated_length: %u", length(), _allocated_heapregions_length); guarantee(_allocated_heapregions_length <= max_length(), "invariant: _allocated_length: %u _max_length: %u", _allocated_heapregions_length, max_length()); bool prev_committed = true; uint num_committed = 0; HeapWord* prev_end = heap_bottom(); for (uint i = 0; i < _allocated_heapregions_length; i++) { if (!is_available(i)) { prev_committed = false; continue; } num_committed++; HeapRegion* hr = _regions.get_by_index(i); guarantee(hr != NULL, "invariant: i: %u", i); guarantee(!prev_committed || hr->bottom() == prev_end, "invariant i: %u " HR_FORMAT " prev_end: " PTR_FORMAT, i, HR_FORMAT_PARAMS(hr), p2i(prev_end)); guarantee(hr->hrm_index() == i, "invariant: i: %u hrm_index(): %u", i, hr->hrm_index()); // Asserts will fire if i is >= _length HeapWord* addr = hr->bottom(); guarantee(addr_to_region(addr) == hr, "sanity"); // We cannot check whether the region is part of a particular set: at the time // this method may be called, we have only completed allocation of the regions, // but not put into a region set. prev_committed = true; prev_end = hr->end(); } for (uint i = _allocated_heapregions_length; i < max_length(); i++) { guarantee(_regions.get_by_index(i) == NULL, "invariant i: %u", i); } guarantee(num_committed == _num_committed, "Found %u committed regions, but should be %u", num_committed, _num_committed); _free_list.verify(); }
int fcloseTIMEOUT_FL(FL_PAR,FILE *fp) { int rcode; if( fileno(fp) < 0 ){ porting_dbg("+++EPIPE[%d] fcloseTIMEOUT() for EOF",fileno(fp)); /* return EOF; 9.8.2 should free the FILE structure. */ rcode = fcloseFILE(fp); return rcode; } /* * 9.8.2 this code is bad leaving FILE and descriptor unclosed. * added in 2.4.8 maybe (?) intented to close disconnected stream * without causing alarm signal for timeout (and buffer flushing ?). if( feof(fp) ) return EOF; */ if( feof(fp) /*|| ferror(fp)*/ ){ if( ferror(fp) || LOG_VERBOSE ) sv1log("-- fcloseTIMEOUT(%X/%d/S%d) EOF=%d ERR=%d\n", p2i(fp),fileno(fp),SocketOf(fileno(fp)),feof(fp),ferror(fp)); dupclosed_FL(FL_BAR,fileno(fp)); rcode = Xfclose(FL_BAR,fp); return rcode; } { fRETURN_ONTIMEOUTX(fp,-1,EOF,LIN_TIMEOUT+2); /* rcode = fclose(fp); */ rcode = Xfclose(FL_BAR,fp); DONE_SUCCESSFULLY(); return rcode; } }
// Print out more verbose output usually for a newly created aot method. void AOTCompiledMethod::print_on(outputStream* st, const char* msg) const { if (st != NULL) { ttyLocker ttyl; st->print("%7d ", (int) st->time_stamp().milliseconds()); st->print("%4d ", _aot_id); // print compilation number st->print(" aot[%2d]", _heap->dso_id()); // Stubs have _method == NULL if (_method == NULL) { st->print(" %s", _name); } else { ResourceMark m; st->print(" %s", _method->name_and_sig_as_C_string()); } if (Verbose) { st->print(" entry at " INTPTR_FORMAT, p2i(_code)); } if (msg != NULL) { st->print(" %s", msg); } st->cr(); } }
inline void vframeStreamCommon::fill_from_compiled_frame(int decode_offset) { _mode = compiled_mode; // Range check to detect ridiculous offsets. if (decode_offset == DebugInformationRecorder::serialized_null || decode_offset < 0 || decode_offset >= nm()->scopes_data_size()) { // 6379830 AsyncGetCallTrace sometimes feeds us wild frames. // If we read nmethod::scopes_data at serialized_null (== 0) // or if read some at other invalid offset, invalid values will be decoded. // Based on these values, invalid heap locations could be referenced // that could lead to crashes in product mode. // Therefore, do not use the decode offset if invalid, but fill the frame // as it were a native compiled frame (no Java-level assumptions). #ifdef ASSERT if (WizardMode) { tty->print_cr("Error in fill_from_frame: pc_desc for " INTPTR_FORMAT " not found or invalid at %d", p2i(_frame.pc()), decode_offset); nm()->print(); nm()->method()->print_codes(); nm()->print_code(); nm()->print_pcs(); } #endif // Provide a cheap fallback in product mode. (See comment above.) found_bad_method_frame(); fill_from_compiled_native_frame(); return; } // Decode first part of scopeDesc DebugInfoReadStream buffer(nm(), decode_offset); _sender_decode_offset = buffer.read_int(); _method = buffer.read_method(); _bci = buffer.read_bci(); assert(_method->is_method(), "checking type of decoded method"); }
inline void vframeStreamCommon::fill_from_compiled_frame(int decode_offset) { _mode = compiled_mode; // Range check to detect ridiculous offsets. if (decode_offset == DebugInformationRecorder::serialized_null || decode_offset < 0 || decode_offset >= nm()->scopes_data_size()) { // 6379830 AsyncGetCallTrace sometimes feeds us wild frames. // If we attempt to read nmethod::scopes_data at serialized_null (== 0), // or if we read some at other crazy offset, // we will decode garbage and make wild references into the heap, // leading to crashes in product mode. // (This isn't airtight, of course, since there are internal // offsets which are also crazy.) #ifdef ASSERT if (WizardMode) { tty->print_cr("Error in fill_from_frame: pc_desc for " INTPTR_FORMAT " not found or invalid at %d", p2i(_frame.pc()), decode_offset); nm()->print(); nm()->method()->print_codes(); nm()->print_code(); nm()->print_pcs(); } #endif // Provide a cheap fallback in product mode. (See comment above.) found_bad_method_frame(); fill_from_compiled_native_frame(); return; } // Decode first part of scopeDesc DebugInfoReadStream buffer(nm(), decode_offset); _sender_decode_offset = buffer.read_int(); _method = buffer.read_method(); _bci = buffer.read_bci(); assert(_method->is_method(), "checking type of decoded method"); }
void ThreadLocalAllocBuffer::print_stats(const char* tag) { Thread* thrd = myThread(); size_t waste = _gc_waste + _slow_refill_waste + _fast_refill_waste; size_t alloc = _number_of_refills * _desired_size; double waste_percent = alloc == 0 ? 0.0 : 100.0 * waste / alloc; size_t tlab_used = Universe::heap()->tlab_used(thrd); gclog_or_tty->print("TLAB: %s thread: " INTPTR_FORMAT " [id: %2d]" " desired_size: " SIZE_FORMAT "KB" " slow allocs: %d refill waste: " SIZE_FORMAT "B" " alloc:%8.5f %8.0fKB refills: %d waste %4.1f%% gc: %dB" " slow: %dB fast: %dB\n", tag, p2i(thrd), thrd->osthread()->thread_id(), _desired_size / (K / HeapWordSize), _slow_allocations, _refill_waste_limit * HeapWordSize, _allocation_fraction.average(), _allocation_fraction.average() * tlab_used / K, _number_of_refills, waste_percent, _gc_waste * HeapWordSize, _slow_refill_waste * HeapWordSize, _fast_refill_waste * HeapWordSize); }
template <class T> void do_oop_work(T* p) { HeapWord* jp = (HeapWord*)p; assert(jp >= _begin && jp < _end, err_msg("Error: jp " PTR_FORMAT " should be within " "[_begin, _end) = [" PTR_FORMAT "," PTR_FORMAT ")", p2i(jp), p2i(_begin), p2i(_end))); oop obj = oopDesc::load_decode_heap_oop(p); if (!(obj == NULL || (HeapWord*)obj >= _boundary)) { tty->print_cr("pointer " PTR_FORMAT " at " PTR_FORMAT " on " "clean card crosses boundary" PTR_FORMAT, p2i((HeapWord*)obj), p2i(jp), p2i(_boundary)); #ifndef PRODUCT obj->print(); #endif had_error = true; } }
inline void assert_different_registers( AbstractRegister a, AbstractRegister b, AbstractRegister c, AbstractRegister d, AbstractRegister e, AbstractRegister f, AbstractRegister g, AbstractRegister h ) { assert( a != b && a != c && a != d && a != e && a != f && a != g && a != h && b != c && b != d && b != e && b != f && b != g && b != h && c != d && c != e && c != f && c != g && c != h && d != e && d != f && d != g && d != h && e != f && e != g && e != h && f != g && f != h && g != h, "registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT ", f=" INTPTR_FORMAT ", g=" INTPTR_FORMAT ", h=" INTPTR_FORMAT "", p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f), p2i(g), p2i(h) ); }
void CompiledIC::set_to_clean(bool in_use) { assert(SafepointSynchronize::is_at_safepoint() || CompiledIC_lock->is_locked() , "MT-unsafe call"); if (TraceInlineCacheClearing || TraceICs) { tty->print_cr("IC@" INTPTR_FORMAT ": set to clean", p2i(instruction_address())); print(); } address entry; if (is_optimized()) { entry = SharedRuntime::get_resolve_opt_virtual_call_stub(); } else { entry = SharedRuntime::get_resolve_virtual_call_stub(); } // A zombie transition will always be safe, since the metadata has already been set to NULL, so // we only need to patch the destination bool safe_transition = !in_use || is_optimized() || SafepointSynchronize::is_at_safepoint(); if (safe_transition) { // Kill any leftover stub we might have too clear_ic_stub(); if (is_optimized()) { set_ic_destination(entry); } else { set_ic_destination_and_value(entry, (void*)NULL); } } else { // Unsafe transition - create stub. InlineCacheBuffer::create_transition_stub(this, NULL, entry); } // We can't check this anymore. With lazy deopt we could have already // cleaned this IC entry before we even return. This is possible if // we ran out of space in the inline cache buffer trying to do the // set_next and we safepointed to free up space. This is a benign // race because the IC entry was complete when we safepointed so // cleaning it immediately is harmless. // assert(is_clean(), "sanity check"); }
void AdaptiveFreeList<Chunk>::verify_stats() const { // The +1 of the LH comparand is to allow some "looseness" in // checking: we usually call this interface when adding a block // and we'll subsequently update the stats; we cannot update the // stats beforehand because in the case of the large-block BT // dictionary for example, this might be the first block and // in that case there would be no place that we could record // the stats (which are kept in the block itself). assert((_allocation_stats.prev_sweep() + _allocation_stats.split_births() + _allocation_stats.coal_births() + 1) // Total Production Stock + 1 >= (_allocation_stats.split_deaths() + _allocation_stats.coal_deaths() + (ssize_t)count()), // Total Current Stock + depletion err_msg("FreeList " PTR_FORMAT " of size " SIZE_FORMAT " violates Conservation Principle: " "prev_sweep(" SIZE_FORMAT ")" " + split_births(" SIZE_FORMAT ")" " + coal_births(" SIZE_FORMAT ") + 1 >= " " split_deaths(" SIZE_FORMAT ")" " coal_deaths(" SIZE_FORMAT ")" " + count(" SSIZE_FORMAT ")", p2i(this), size(), _allocation_stats.prev_sweep(), _allocation_stats.split_births(), _allocation_stats.split_births(), _allocation_stats.split_deaths(), _allocation_stats.coal_deaths(), count())); }
void ClassLoadingService::notify_class_unloaded(InstanceKlass* k) { DTRACE_CLASSLOAD_PROBE(unloaded, k, false); // Classes that can be unloaded must be non-shared _classes_unloaded_count->inc(); if (UsePerfData) { // add the class size size_t size = compute_class_size(k); _classbytes_unloaded->inc(size); // Compute method size & subtract from running total. // We are called during phase 1 of mark sweep, so it's // still ok to iterate through Method*s here. Array<Method*>* methods = k->methods(); for (int i = 0; i < methods->length(); i++) { _class_methods_size->inc(-methods->at(i)->size()); } } if (TraceClassUnloading) { ResourceMark rm; tty->print_cr("[Unloading class %s " INTPTR_FORMAT "]", k->external_name(), p2i(k)); } }
inline void assert_different_registers( AbstractRegister a, AbstractRegister b, AbstractRegister c, AbstractRegister d, AbstractRegister e, AbstractRegister f ) { assert( a != b && a != c && a != d && a != e && a != f && b != c && b != d && b != e && b != f && c != d && c != e && c != f && d != e && d != f && e != f, err_msg_res("registers must be different: a=" INTPTR_FORMAT ", b=" INTPTR_FORMAT ", c=" INTPTR_FORMAT ", d=" INTPTR_FORMAT ", e=" INTPTR_FORMAT ", f=" INTPTR_FORMAT "", p2i(a), p2i(b), p2i(c), p2i(d), p2i(e), p2i(f)) ); }
inline void CompactibleSpace::scan_and_adjust_pointers(SpaceType* space) { // adjust all the interior pointers to point at the new locations of objects // Used by MarkSweep::mark_sweep_phase3() HeapWord* cur_obj = space->bottom(); HeapWord* const end_of_live = space->_end_of_live; // Established by "scan_and_forward". HeapWord* const first_dead = space->_first_dead; // Established by "scan_and_forward". assert(first_dead <= end_of_live, "Stands to reason, no?"); const intx interval = PrefetchScanIntervalInBytes; debug_only(HeapWord* prev_obj = NULL); while (cur_obj < end_of_live) { Prefetch::write(cur_obj, interval); if (cur_obj < first_dead || oop(cur_obj)->is_gc_marked()) { // cur_obj is alive // point all the oops to the new location size_t size = MarkSweep::adjust_pointers(oop(cur_obj)); size = space->adjust_obj_size(size); debug_only(prev_obj = cur_obj); cur_obj += size; } else { debug_only(prev_obj = cur_obj); // cur_obj is not a live object, instead it points at the next live object cur_obj = *(HeapWord**)cur_obj; assert(cur_obj > prev_obj, "we should be moving forward through memory, cur_obj: " PTR_FORMAT ", prev_obj: " PTR_FORMAT, p2i(cur_obj), p2i(prev_obj)); } } assert(cur_obj == end_of_live, "just checking"); }
void trace_method_handle_stub(const char* adaptername, oopDesc* mh, intptr_t* entry_sp, intptr_t* saved_regs) { bool has_mh = (strstr(adaptername, "/static") == NULL && strstr(adaptername, "linkTo") == NULL); // static linkers don't have MH const char* mh_reg_name = has_mh ? "R23_method_handle" : "G23"; tty->print_cr("MH %s %s="INTPTR_FORMAT " sp=" INTPTR_FORMAT, adaptername, mh_reg_name, p2i(mh), p2i(entry_sp)); if (Verbose) { tty->print_cr("Registers:"); const int abi_offset = frame::abi_reg_args_size / 8; for (int i = R3->encoding(); i <= R12->encoding(); i++) { Register r = as_Register(i); int count = i - R3->encoding(); // The registers are stored in reverse order on the stack (by save_volatile_gprs(R1_SP, abi_reg_args_size)). tty->print("%3s=" PTR_FORMAT, r->name(), saved_regs[abi_offset + count]); if ((count + 1) % 4 == 0) { tty->cr(); } else { tty->print(", "); } } tty->cr(); { // dumping last frame with frame::describe JavaThread* p = JavaThread::active(); ResourceMark rm; PRESERVE_EXCEPTION_MARK; // may not be needed by safer and unexpensive here FrameValues values; // Note: We want to allow trace_method_handle from any call site. // While trace_method_handle creates a frame, it may be entered // without a PC on the stack top (e.g. not just after a call). // Walking that frame could lead to failures due to that invalid PC. // => carefully detect that frame when doing the stack walking // Current C frame frame cur_frame = os::current_frame(); // Robust search of trace_calling_frame (independant of inlining). // Assumes saved_regs comes from a pusha in the trace_calling_frame. assert(cur_frame.sp() < saved_regs, "registers not saved on stack ?"); frame trace_calling_frame = os::get_sender_for_C_frame(&cur_frame); while (trace_calling_frame.fp() < saved_regs) { trace_calling_frame = os::get_sender_for_C_frame(&trace_calling_frame); } // Safely create a frame and call frame::describe. intptr_t *dump_sp = trace_calling_frame.sender_sp(); frame dump_frame = frame(dump_sp); dump_frame.describe(values, 1); values.describe(-1, saved_regs, "raw top of stack"); tty->print_cr("Stack layout:"); values.print(p); } if (has_mh && mh->is_oop()) { mh->print(); if (java_lang_invoke_MethodHandle::is_instance(mh)) { if (java_lang_invoke_MethodHandle::form_offset_in_bytes() != 0) java_lang_invoke_MethodHandle::form(mh)->print(); } } } }
// These stubs are used by the compiler only. // Argument registers, which must be preserved: // rcx - receiver (always first argument) // rdx - second argument (if any) // Other registers that might be usable: // rax - inline cache register (is interface for itable stub) // rbx - method (used when calling out to interpreter) // Available now, but may become callee-save at some point: // rsi, rdi // Note that rax and rdx are also used for return values. // VtableStub* VtableStubs::create_vtable_stub(int vtable_index) { const int i486_code_length = VtableStub::pd_code_size_limit(true); VtableStub* s = new(i486_code_length) VtableStub(true, vtable_index); // Can be NULL if there is no free space in the code cache. if (s == NULL) { return NULL; } ResourceMark rm; CodeBuffer cb(s->entry_point(), i486_code_length); MacroAssembler* masm = new MacroAssembler(&cb); #ifndef PRODUCT if (CountCompiledCalls) { __ incrementl(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr())); } #endif /* PRODUCT */ // get receiver (need to skip return address on top of stack) assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx"); // get receiver klass address npe_addr = __ pc(); __ movptr(rax, Address(rcx, oopDesc::klass_offset_in_bytes())); #ifndef PRODUCT if (DebugVtables) { Label L; // check offset vs vtable length __ cmpl(Address(rax, InstanceKlass::vtable_length_offset()*wordSize), vtable_index*vtableEntry::size()); __ jcc(Assembler::greater, L); __ movl(rbx, vtable_index); __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), rcx, rbx); __ bind(L); } #endif // PRODUCT const Register method = rbx; // load Method* and target address __ lookup_virtual_method(rax, vtable_index, method); if (DebugVtables) { Label L; __ cmpptr(method, (int32_t)NULL_WORD); __ jcc(Assembler::equal, L); __ cmpptr(Address(method, Method::from_compiled_offset()), (int32_t)NULL_WORD); __ jcc(Assembler::notZero, L); __ stop("Vtable entry is NULL"); __ bind(L); } // rax,: receiver klass // method (rbx): Method* // rcx: receiver address ame_addr = __ pc(); __ jmp( Address(method, Method::from_compiled_offset())); masm->flush(); if (PrintMiscellaneous && (WizardMode || Verbose)) { tty->print_cr("vtable #%d at "PTR_FORMAT"[%d] left over: %d", vtable_index, p2i(s->entry_point()), (int)(s->code_end() - s->entry_point()), (int)(s->code_end() - __ pc())); } guarantee(__ pc() <= s->code_end(), "overflowed buffer"); // shut the door on sizing bugs int slop = 3; // 32-bit offset is this much larger than an 8-bit one assert(vtable_index > 10 || __ pc() + slop <= s->code_end(), "room for 32-bit offset"); s->set_exception_points(npe_addr, ame_addr); return s; }
VtableStub* VtableStubs::create_itable_stub(int itable_index) { // Note well: pd_code_size_limit is the absolute minimum we can get away with. If you // add code here, bump the code stub size returned by pd_code_size_limit! const int i486_code_length = VtableStub::pd_code_size_limit(false); VtableStub* s = new(i486_code_length) VtableStub(false, itable_index); // Can be NULL if there is no free space in the code cache. if (s == NULL) { return NULL; } ResourceMark rm; CodeBuffer cb(s->entry_point(), i486_code_length); MacroAssembler* masm = new MacroAssembler(&cb); // Entry arguments: // rax,: Interface // rcx: Receiver #ifndef PRODUCT if (CountCompiledCalls) { __ incrementl(ExternalAddress((address) SharedRuntime::nof_megamorphic_calls_addr())); } #endif /* PRODUCT */ // get receiver (need to skip return address on top of stack) assert(VtableStub::receiver_location() == rcx->as_VMReg(), "receiver expected in rcx"); // get receiver klass (also an implicit null-check) address npe_addr = __ pc(); __ movptr(rsi, Address(rcx, oopDesc::klass_offset_in_bytes())); // Most registers are in use; we'll use rax, rbx, rsi, rdi // (If we need to make rsi, rdi callee-save, do a push/pop here.) const Register method = rbx; Label throw_icce; // Get Method* and entrypoint for compiler __ lookup_interface_method(// inputs: rec. class, interface, itable index rsi, rax, itable_index, // outputs: method, scan temp. reg method, rdi, throw_icce); // method (rbx): Method* // rcx: receiver #ifdef ASSERT if (DebugVtables) { Label L1; __ cmpptr(method, (int32_t)NULL_WORD); __ jcc(Assembler::equal, L1); __ cmpptr(Address(method, Method::from_compiled_offset()), (int32_t)NULL_WORD); __ jcc(Assembler::notZero, L1); __ stop("Method* is null"); __ bind(L1); } #endif // ASSERT address ame_addr = __ pc(); __ jmp(Address(method, Method::from_compiled_offset())); __ bind(throw_icce); __ jump(RuntimeAddress(StubRoutines::throw_IncompatibleClassChangeError_entry())); masm->flush(); if (PrintMiscellaneous && (WizardMode || Verbose)) { tty->print_cr("itable #%d at "PTR_FORMAT"[%d] left over: %d", itable_index, p2i(s->entry_point()), (int)(s->code_end() - s->entry_point()), (int)(s->code_end() - __ pc())); } guarantee(__ pc() <= s->code_end(), "overflowed buffer"); // shut the door on sizing bugs int slop = 3; // 32-bit offset is this much larger than an 8-bit one assert(itable_index > 10 || __ pc() + slop <= s->code_end(), "room for 32-bit offset"); s->set_exception_points(npe_addr, ame_addr); return s; }
void G1PageBasedVirtualSpace::initialize_with_page_size(ReservedSpace rs, size_t used_size, size_t page_size) { guarantee(rs.is_reserved(), "Given reserved space must have been reserved already."); vmassert(_low_boundary == NULL, "VirtualSpace already initialized"); vmassert(page_size > 0, "Page size must be non-zero."); guarantee(is_ptr_aligned(rs.base(), page_size), "Reserved space base " PTR_FORMAT " is not aligned to requested page size " SIZE_FORMAT, p2i(rs.base()), page_size); guarantee(is_size_aligned(used_size, os::vm_page_size()), "Given used reserved space size needs to be OS page size aligned (%d bytes) but is " SIZE_FORMAT, os::vm_page_size(), used_size); guarantee(used_size <= rs.size(), "Used size of reserved space " SIZE_FORMAT " bytes is smaller than reservation at " SIZE_FORMAT " bytes", used_size, rs.size()); guarantee(is_size_aligned(rs.size(), page_size), "Expected that the virtual space is size aligned, but " SIZE_FORMAT " is not aligned to page size " SIZE_FORMAT, rs.size(), page_size); _low_boundary = rs.base(); _high_boundary = _low_boundary + used_size; _special = rs.special(); _executable = rs.executable(); _page_size = page_size; vmassert(_committed.size() == 0, "virtual space initialized more than once"); BitMap::idx_t size_in_pages = rs.size() / page_size; _committed.initialize(size_in_pages); if (_special) { _dirty.initialize(size_in_pages); } _tail_size = used_size % _page_size; }
int gzipFilterX(FILE *in,FILE *out,SyncXF syncf,void *sp,int si){ gzFile gz; int len,rcc; CStr(buf,1024*8); int size; int gsize; int wcc; int bcc = 0; double Start = Time(); double Prevf = 0; int ibz = sizeof(buf); int gi; int fd = -1; int ofd = fileno(out); int xfd; int zerr = 0; /* int rready = -1; */ errno = 0; fd = dup(fileno(out)); if( fd < 0 ){ syslog_ERROR("--gzipFilter[%d]<-[%d] errno=%d\n",fd,ofd,errno); return -1; } /* if( 0 <= GZIPready ) rready = dup(GZIPready); */ len = 0; /* if( gz = GZdopen(dup(fileno(out)),"w") ){ */ if( file_isSOCKET(ofd) || file_ISSOCK(ofd) ) if( !IsConnected(ofd,NULL) || !IsAlive(ofd) ){ fprintf(stderr,"[%d.%X] gzip DISCONN\n",getpid(),getthreadid()); fprintf(stderr,"[%d.%X] gzip DISCONN fd[%d] con=%d isSOCK=%d,%d,%d\n", getpid(),getthreadid(),ofd,IsConnected(ofd,NULL), file_isSOCKET(ofd),file_ISSOCK(ofd),file_issock(ofd)); sendsync(rready,1); close(fd); return -1; } gz = GZdopen(fd,"w"); if( file_isSOCKET(ofd) || file_ISSOCK(ofd) ) if( !IsConnected(ofd,NULL) || !IsAlive(ofd) ){ fprintf(stderr,"[%d.%X] gzip DISCONN gx=%d\n",getpid(),getthreadid(),p2i(gz)); fprintf(stderr,"[%d.%X] gzip DISCONN fd[%d] con=%d isSOCK=%d,%d,%d\n", getpid(),getthreadid(),ofd,IsConnected(ofd,NULL), file_isSOCKET(ofd),file_ISSOCK(ofd),file_issock(ofd)); close(fd); sendsync(rready,2); close(fd); return -1; } if( gz ){ LOGX_gzip++; if( Gzip_NoFlush ){ GZDBG(stderr,"-- %X gzip flush disabled(%d)\n", TID,Gzip_NoFlush); } Prevf = Time(); sendsync(rready,0); setCloseOnFork("GZIPstart",fd); /* while( rcc = fread(buf,1,sizeof(buf),in) ){ */ for( gi = 0;; gi++ ){ if( gotsigTERM("gzip gi=%d",gi) ){ if( numthreads() && !ismainthread() ){ thread_exit(0); } break; } if( !Gzip_NoFlush ) if( bcc ) if( 0 < len && finputReady(in,NULL) == 0 ){ zerr = gzflush(gz,Z_SYNC_FLUSH); if( zerr ){ porting_dbg("+++EPIPE[%d] gzflush() zerr=%d %d SIG*%d",fd,zerr,len,gotSIGPIPE()); } bcc = 0; } if( lSINGLEP() ) /* could be generic */ { if( 0 < len ) if( !Gzip_NoFlush || 4 < gi && 5 < Time()-Prevf ){ GZDBG(stderr,"-- %X gzip flush %d(%f) %d/%d\n", TID,Gzip_NoFlush,Time()-Start,len,gi); Prevf = Time(); zerr = gzflush(gz,Z_SYNC_FLUSH); bcc = 0; if( zerr ){ GZDBG(stderr,"-- %X gzip gzflush()%d err=%d\n", TID,len,zerr); break; } } } /* rcc = fread(buf,1,sizeof(buf),in); */ rcc = xread(in,AVStr(buf),QVSSize(buf,ibz)); if( rcc <= 0 ){ break; } wcc = gzwrite(gz,buf,rcc); //fprintf(stderr,"[%d] Gzwrite %d/%d / %d\n",getpid(),wcc,rcc,len); if( wcc <= 0 ){ porting_dbg("+++EPIPE[%d] gzwrite() %d/%d %d SIG*%d",fd,wcc,rcc,len,gotSIGPIPE()); fprintf(stderr,"[%d] Gzwrite %d/%d / %d\n",getpid(),wcc,rcc,len); break; } if( wcc != rcc ){ syslog_ERROR("gzwrite %d/%d\n",wcc,rcc); } if( 0 < wcc ){ bcc += wcc; } if( sizeof(buf) <= len ){ ibz = sizeof(buf); } if( !Gzip_NoFlush ) if( bcc ) if( sizeof(buf) <= bcc || len < 16*1024 ){ zerr = gzflush(gz,Z_SYNC_FLUSH); bcc = 0; } if( zerr || gotSIGPIPE() ){ porting_dbg("+++EPIPE[%d] gzflush() zerr=%d %d SIG*%d",fd,zerr,len,gotSIGPIPE()); break; } len += rcc; } if( len == 0 ){ const char *em; int en; int ef; em = gzerror(gz,&en); ef = gzeof(gz); if( en == -1 /* see errno */ && errno == 0 ){ /* no error */ }else{ daemonlog("F","FATAL: gzwrite(%d)=%d/%d eof=%d %d %s\n", fd,len,bcc,ef,en,em); porting_dbg("FATAL: gzwrite(%d)=%d/%d eof=%d %d %s", fd,len,bcc,ef,en,em); } } clearCloseOnFork("GZIPend",fd); gzflush(gz,Z_SYNC_FLUSH); xfd = dup(fd); gsize = GZtell(gz); GZclose(gz); if( isWindowsCE() || lMULTIST() ){ /* duplicated close of fd is harmful */ }else if( isWindows() ) close(fd); /* to clear osf-handle mapping */ Lseek(xfd,0,2); size = Lseek(xfd,0,1); Lseek(xfd,0,0); close(xfd); syslog_DEBUG("(%f)gzipFilter %d -> %d / %d\n",Time()-Start, len,gsize,size); return len; } sendsync(rready,3); close(fd); return 0; }
bool G1BlockOffsetSharedArray::is_card_boundary(HeapWord* p) const { assert(p >= _reserved.start(), "just checking"); size_t delta = pointer_delta(p, _reserved.start()); return (delta & right_n_bits(LogN_words)) == (size_t)NoBits; } #ifdef ASSERT void G1BlockOffsetSharedArray::check_index(size_t index, const char* msg) const { assert((index) < (_reserved.word_size() >> LogN_words), err_msg("%s - index: " SIZE_FORMAT ", _vs.committed_size: " SIZE_FORMAT, msg, (index), (_reserved.word_size() >> LogN_words))); assert(G1CollectedHeap::heap()->is_in_exact(address_for_index_raw(index)), err_msg("Index " SIZE_FORMAT " corresponding to " PTR_FORMAT " (%u) is not in committed area.", (index), p2i(address_for_index_raw(index)), G1CollectedHeap::heap()->addr_to_region(address_for_index_raw(index)))); } #endif // ASSERT ////////////////////////////////////////////////////////////////////// // G1BlockOffsetArray ////////////////////////////////////////////////////////////////////// G1BlockOffsetArray::G1BlockOffsetArray(G1BlockOffsetSharedArray* array, MemRegion mr) : G1BlockOffsetTable(mr.start(), mr.end()), _unallocated_block(_bottom), _array(array), _gsp(NULL) { assert(_bottom <= _end, "arguments out of order"); }
inline void CompactibleSpace::scan_and_compact(SpaceType* space) { // Copy all live objects to their new location // Used by MarkSweep::mark_sweep_phase4() verify_up_to_first_dead(space); HeapWord* const end_of_live = space->_end_of_live; assert(space->_first_dead <= end_of_live, "Invariant. _first_dead: " PTR_FORMAT " <= end_of_live: " PTR_FORMAT, p2i(space->_first_dead), p2i(end_of_live)); if (space->_first_dead == end_of_live && !oop(space->bottom())->is_gc_marked()) { // Nothing to compact. The space is either empty or all live object should be left in place. clear_empty_region(space); return; } const intx scan_interval = PrefetchScanIntervalInBytes; const intx copy_interval = PrefetchCopyIntervalInBytes; assert(space->bottom() < end_of_live, "bottom: " PTR_FORMAT " should be < end_of_live: " PTR_FORMAT, p2i(space->bottom()), p2i(end_of_live)); HeapWord* cur_obj = space->bottom(); if (space->_first_dead > cur_obj && !oop(cur_obj)->is_gc_marked()) { // All object before _first_dead can be skipped. They should not be moved. // A pointer to the first live object is stored at the memory location for _first_dead. cur_obj = *(HeapWord**)(space->_first_dead); } debug_only(HeapWord* prev_obj = NULL); while (cur_obj < end_of_live) { if (!oop(cur_obj)->is_gc_marked()) { debug_only(prev_obj = cur_obj); // The first word of the dead object contains a pointer to the next live object or end of space. cur_obj = *(HeapWord**)cur_obj; assert(cur_obj > prev_obj, "we should be moving forward through memory"); } else { // prefetch beyond q Prefetch::read(cur_obj, scan_interval); // size and destination size_t size = space->obj_size(cur_obj); HeapWord* compaction_top = (HeapWord*)oop(cur_obj)->forwardee(); // prefetch beyond compaction_top Prefetch::write(compaction_top, copy_interval); // copy object and reinit its mark assert(cur_obj != compaction_top, "everything in this pass should be moving"); Copy::aligned_conjoint_words(cur_obj, compaction_top, size); oop(compaction_top)->init_mark(); assert(oop(compaction_top)->klass() != NULL, "should have a class"); debug_only(prev_obj = cur_obj); cur_obj += size; } } clear_empty_region(space); }
void PLAB::print() { gclog_or_tty->print_cr("PLAB: _bottom: " PTR_FORMAT " _top: " PTR_FORMAT " _end: " PTR_FORMAT " _hard_end: " PTR_FORMAT ")", p2i(_bottom), p2i(_top), p2i(_end), p2i(_hard_end)); }
int gunzipFilterX(FILE *in,FILE *out,SyncF syncf,void *sp,int si){ gzFile gz; int rcc; int wcc; int werr; CStr(buf,1024*8); int size; double Start = Time(); const char *em; int en; int ef; int ready; int rd; int eof = 0; int nonblock; int serrno = 0; int ibz = sizeof(buf); int gi; int fd = -1; inlen = 0; errno = 0; fd = dup(fileno(in)); if( isWindows() ){ int pollPipe(int,int); nonblock = 0; ready = fPollIn(in,10*1000); gz = GZdopen(fd,"r"); if( gz == 0 ) syslog_ERROR("##gunzipFilter[%d/%d] gz=%X ready=%d/%d\n", fd,fileno(in),p2i(gz),ready,pollPipe(fd,1)); }else{ /* * to make smooth streaming of data relayed on narrow network * apply NBIO to gzopen() which will do fread() at the start. * applying NBIO also to gzread() seems to break the gzip. */ /* setNonblockingIO(fileno(in),1); */ setNonblockingIO(fd,1); nonblock = 1; ready = fPollIn(in,10*1000); if( ready == 0 ){ fprintf(stderr,"----[%d] gunzipFilter: ready[%d]=%d\n", getpid(),fileno(in),ready); } /* gz = GZdopen(fd = dup(fileno(in)),"r"); */ gz = GZdopen(fd,"r"); if( DGzlibVer == 0 ) { /* setNonblockingIO(fileno(in),0); */ setNonblockingIO(fd,0); nonblock = 0; } } if( syncf != 0 ){ syslog_ERROR("--- gunzipFX SYNC %X(%X,%d)\n",xp2i(syncf),p2i(sp),si); (*syncf)(sp,si); } ibz = 1024; //ibz = 256; size = 0; /* if( gz = GZdopen(dup(fileno(in)),"r") ){ */ if( gz ){ LOGX_gunzip++; setCloseOnFork("GUNZIPstart",fd); em = gzerror(gz,&en); /* while( 0 < (rcc = gzread(gz,buf,sizeof(buf))) ){ */ for( gi = 0;; gi++ ){ if( gotsigTERM("gunzip gi=%d em=%X",gi,p2i(em)) ){ if( numthreads() ){ if( em ){ putfLog("thread-gunzip gi=%d _exit() em=(%s)",gi,em?em:""); _exit(0); } thread_exit(0); } break; } if( nonblock ){ if( 0 < gi ){ /* setNonblockingIO(fileno(in),0); */ setNonblockingIO(fd,0); nonblock = 0; } } /* if( 0 < size && inputReady(fileno(in),NULL) == 0 ){ */ /* if( 0 < size && inputReady(fd,NULL) == 0 ){ */ if( eof == 0 ) if( 0 < size ) if( ready = inputReady(fd,&rd) ){ if( ready == 2 ){ /* both PS_IN and PS_PRI */ eof = 1; } }else{ //fprintf(stderr,"[%d] -- gzread#%d %d / %d FLUSH\n",getpid(),gi,rcc,size); fflush(out); } ready = fPollIn(in,10*1000); errno = 0; rcc = gzread(gz,buf,QVSSize(buf,ibz)); serrno = errno; if( rcc <= 0 ){ break; } //fprintf(stderr,"[%d] -- gzread %d / %d\n",getpid(),rcc,size); wcc = fwrite(buf,1,rcc,out); /* this fflush seems significant */ werr = fflush(out); if( wcc < rcc || werr || ferror(out) || gotSIGPIPE() ){ porting_dbg("+++EPIPE[%d] gunzip fwrite() %d/%d err=%d/%d %d SIG*%d",fileno(out),wcc,rcc,werr,ferror(out),size,gotSIGPIPE()); break; } size += rcc; if( size < sizeof(buf) ){ fflush(out); }else{ ibz = sizeof(buf); } } fflush(out); if( rcc < 0 || size == 0 ){ em = gzerror(gz,&en); ef = gzeof(gz); if( en == -1 /* see errno */ && serrno == 0 ){ /* no error */ }else{ daemonlog("F","FATAL: gzread(%d)=%d/%d eof=%d %d %s %d\n", fd,rcc,size,ef,en,em,serrno); porting_dbg("FATAL: gzread(%d)=%d/%d eof=%d %d %s", fd,rcc,size,ef,en,em); if( lTHREAD() ) fprintf(stderr,"--[%d]gzread(%d)=%d/%d eof=%d %d %s\n", getpid(),fd,rcc,size,ef,en,em); } } clearCloseOnFork("GUNZIPend",fd); GZclose(gz); if( isWindowsCE() || lMULTIST() ){ /* duplicated close of fd is harmful */ }else if( isWindows() ) close(fd); fseek(out,0,0); syslog_DEBUG("(%f)gunzipFilter -> %d\n",Time()-Start,size); if( lTHREAD() ) if( 0 < inlen ) syslog_ERROR("###GUNZIP filter %d/%d\n",inlen,size); return size; } return 0; }
uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) { uint found = 0; size_t length_found = 0; uint cur = 0; while (length_found < num && cur < max_length()) { HeapRegion* hr = _regions.get_by_index(cur); if ((!empty_only && !is_available(cur)) || (is_available(cur) && hr != NULL && hr->is_empty())) { // This region is a potential candidate for allocation into. length_found++; } else { // This region is not a candidate. The next region is the next possible one. found = cur + 1; length_found = 0; } cur++; } if (length_found == num) { for (uint i = found; i < (found + num); i++) { HeapRegion* hr = _regions.get_by_index(i); // sanity check guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()), "Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr)); } return found; } else { return G1_NO_HRM_INDEX; } }
void Zfree(void *ptr){ free(ptr); GZDBG(stderr,"-- %4X Zfree(%X)\n",TID,p2i(ptr)); }
void GameStateArea::handleEvent(sf::Event& event) { if(subState == SubState::GAME) { if(event.type == sf::Event::KeyPressed) { // Open the start menu if(event.key.code == sf::Keyboard::Return) { subState = SubState::START; startMenu.select(0, '*'); } // Activate adjacent objects if(event.key.code == sf::Keyboard::Space) { // Search for nearby chests for(auto& chest : area->chests) { sf::Vector2f p1 = chest.getPosition(); sf::Vector2f p2 = player->mover->getPosition(); sf::Vector2i p1i(static_cast<int>(p1.x), static_cast<int>(p1.y)); sf::Vector2i p2i(static_cast<int>(p2.x), static_cast<int>(p2.y)); switch(player->mover->getFacing()) { case Direction::NORTH: if(p1i.x == p2i.x && p1i.y == p2i.y-1) openChest(chest); break; case Direction::EAST: if(p1i.y == p2i.y && p1i.x == p2i.x+1) openChest(chest); break; case Direction::SOUTH: if(p1i.x == p2i.x && p1i.y == p2i.y+1) openChest(chest); break; case Direction::WEST: if(p1i.y == p2i.y && p1i.x == p2i.x-1) openChest(chest); break; default: break; } } } } } else if(subState == SubState::START) { if(event.type == sf::Event::KeyPressed) { // Handle menu navigation if(event.key.code == sf::Keyboard::Up) startMenu.navigate(gui::Direction::UP, gui::NavigationMode::STOP, gui::NavigationMode::LOOP); else if(event.key.code == sf::Keyboard::Right) startMenu.navigate(gui::Direction::RIGHT, gui::NavigationMode::STOP, gui::NavigationMode::LOOP); else if(event.key.code == sf::Keyboard::Down) startMenu.navigate(gui::Direction::DOWN, gui::NavigationMode::STOP, gui::NavigationMode::LOOP); else if(event.key.code == sf::Keyboard::Left) startMenu.navigate(gui::Direction::LEFT, gui::NavigationMode::STOP, gui::NavigationMode::LOOP); // Open a menu option else if(event.key.code == sf::Keyboard::Return || event.key.code == sf::Keyboard::Space) startMenu.activate(this); // Close the menu else if(event.key.code == sf::Keyboard::Escape) { subState = SubState::GAME; } } } else if(subState == SubState::INFO) { if(event.type == sf::Event::KeyPressed) { if(event.key.code == sf::Keyboard::Return || event.key.code == sf::Keyboard::Space) { if(infoMsgBox.getPage() == infoMsgBox.numPages()-1) subState = SubState::GAME; else infoMsgBox.setPage(infoMsgBox.getPage()+1); } } } }
static void sendsyncX(SyncXF syncf,void *sp,int si,int code){ if( syncf != 0 ){ syslog_ERROR("--- gzipFX SYNC %X(%X,%d,%d)\n",xp2i(syncf),p2i(sp),si,code); (*syncf)(sp,si,code); } }