/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "memory/allocation.hpp"
// There are various techniques that require threads to be able to log
// addresses. For example, a generational write barrier might log
// the addresses of modified old-generation objects. This type supports
// this operation.
// The definition of placement operator new(size_t, void*) in the <new>.
#include <new>
class PtrQueueSet;
protected:
// The ptr queue set to which this queue belongs.
// Whether updates should be logged.
bool _active;
// The buffer.
void** _buf;
// The index at which an object was last enqueued. Starts at "_sz"
// (indicating an empty buffer) and goes towards zero.
// The size of the buffer.
// If true, the queue is permanent, and doesn't need to deallocate
// its buffer in the destructor (since that obtains a lock which may not
// be legally locked by then.
bool _perm;
// If there is a lock associated with this buffer, this is that lock.
public:
// Initialize this queue to contain a null buffer, and be part of the
// given PtrQueueSet.
// Release any contained resources.
virtual void flush();
// Calls flush() when destroyed.
// Associate a lock with a ptr queue.
// Enqueues the given "obj".
if (!_active) return;
else enqueue_known_active(ptr);
}
// This method is called when we're doing the zero index handling
// and gives a chance to the queues to do any pre-enqueueing
// processing they might want to do on the buffer. It should return
// true if the buffer should be enqueued, or false if enough
// entries were cleared from it so that it can be re-used. It should
// not return false if the buffer is still full (otherwise we can
// get into an infinite loop).
virtual bool should_enqueue_buffer() { return true; }
void handle_zero_index();
void locking_enqueue_completed_buffer(void** buf);
void enqueue_known_active(void* ptr);
}
bool is_empty() {
}
// Set the "active" property of the queue to "b". An enqueue to an
// inactive thread is a no-op. Setting a queue to inactive resets its
// log to the empty state.
void set_active(bool b) {
_active = b;
}
}
}
}
// To support compiler.
}
}
}
};
class BufferNode {
public:
// Align the size of the structure to the size of the pointer
return alignment;
}
// BufferNode is allocated before the buffer.
// The chunk of memory that holds both of them is a block.
// Produce a new BufferNode given a buffer.
}
// The following are the required conversion routines:
}
return make_buffer_from_block(node);
}
return (void*)node;
}
static void** make_buffer_from_block(void* p) {
return (void**)((char*)p + aligned_size());
}
static void* make_block_from_buffer(void** p) {
return (void*)((char*)p - aligned_size());
}
};
// A PtrQueueSet represents resources common to a set of pointer queues.
// In particular, the individual queues allocate buffers from this shared
// set, and return completed buffers to the set.
// All these variables are are protected by the TLOQ_CBL_mon. XXX ???
protected:
int _n_completed_buffers;
volatile bool _process_completed;
// This (and the interpretation of the first element as a "next"
// pointer) are protected by the TLOQ_FL_lock.
// Queue set can share a freelist. The _fl_owner variable
// specifies the owner. It is set to "this" by default.
// The size of all buffers in the set.
bool _all_active;
// If true, notify_all on _cbl_mon when the threshold is reached.
bool _notify_when_complete;
// Maximum number of elements allowed on completed queue: after that,
// enqueuer does the work itself. Zero indicates no maximum.
int _max_completed_queue;
protected:
// A mutator thread does the the work of processing a buffer.
// Returns "true" iff the work is complete (and the buffer may be
// deallocated).
return false;
}
public:
// Create an empty ptr queue set.
PtrQueueSet(bool notify_when_complete = false);
// Because of init-order concerns, we can't pass these as constructor
// arguments.
int max_completed_queue,
}
// Return an empty oop array of size _sz (required to be non-zero).
void** allocate_buffer();
// Return an empty buffer to the free list. The "buf" argument is
// required to be a pointer to the head of an array of length "_sz".
void deallocate_buffer(void** buf);
// Declares that "buf" is a complete buffer.
// To be invoked by the mutator.
bool process_or_enqueue_complete_buffer(void** buf);
bool completed_buffers_exist_dirty() {
return _n_completed_buffers > 0;
}
// Set the buffer size. Should be called before any "enqueue" operation
// can be called. And should only be called once.
// Get the buffer size.
// Must only be called at a safe point. Indicates that the buffer free
// list size may be reduced, if that is deemed desirable.
void reduce_free_list();
// Notify the consumer if the number of buffers crossed the threshold
void notify_if_necessary();
};
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_PTRQUEUE_HPP