@@ -94,47 +94,42 @@ void MutableNUMASpace::ensure_parsability() {
9494
9595size_t MutableNUMASpace::used_in_words () const {
9696 size_t s = 0 ;
97- for (int i = 0 ; i < lgrp_spaces ()-> length (); i++ ) {
98- s += lgrp_spaces ()-> at (i) ->space ()->used_in_words ();
97+ for (LGRPSpace* ls : * lgrp_spaces ()) {
98+ s += ls ->space ()->used_in_words ();
9999 }
100100 return s;
101101}
102102
103103size_t MutableNUMASpace::free_in_words () const {
104104 size_t s = 0 ;
105- for (int i = 0 ; i < lgrp_spaces ()-> length (); i++ ) {
106- s += lgrp_spaces ()-> at (i) ->space ()->free_in_words ();
105+ for (LGRPSpace* ls : * lgrp_spaces ()) {
106+ s += ls ->space ()->free_in_words ();
107107 }
108108 return s;
109109}
110110
111- MutableNUMASpace::LGRPSpace *MutableNUMASpace::lgrp_space_for_thread (Thread* thr) const {
112- guarantee (thr != nullptr , " No thread" );
113-
114- int lgrp_id = thr->lgrp_id ();
115- assert (lgrp_id != -1 , " lgrp_id must be set during thread creation" );
116-
117- int lgrp_spaces_index = lgrp_spaces ()->find_if ([&](LGRPSpace* space) {
118- return space->lgrp_id () == (uint)lgrp_id;
119- });
120-
121- if (lgrp_spaces_index == -1 ) {
122- // Running on a CPU with no memory; pick another CPU based on %.
123- lgrp_spaces_index = lgrp_id % lgrp_spaces ()->length ();
111+ size_t MutableNUMASpace::tlab_capacity (Thread *ignored) const {
112+ size_t s = 0 ;
113+ for (LGRPSpace* ls : *lgrp_spaces ()) {
114+ s += ls->space ()->capacity_in_bytes ();
124115 }
125- return lgrp_spaces ()->at (lgrp_spaces_index);
126- }
127-
128- size_t MutableNUMASpace::tlab_capacity (Thread *thr) const {
129- return lgrp_space_for_thread (thr)->space ()->capacity_in_bytes ();
116+ return s / (size_t )lgrp_spaces ()->length ();
130117}
131118
132- size_t MutableNUMASpace::tlab_used (Thread *thr) const {
133- return lgrp_space_for_thread (thr)->space ()->used_in_bytes ();
119+ size_t MutableNUMASpace::tlab_used (Thread *ignored) const {
120+ size_t s = 0 ;
121+ for (LGRPSpace* ls : *lgrp_spaces ()) {
122+ s += ls->space ()->used_in_bytes ();
123+ }
124+ return s / (size_t )lgrp_spaces ()->length ();
134125}
135126
136- size_t MutableNUMASpace::unsafe_max_tlab_alloc (Thread *thr) const {
137- return lgrp_space_for_thread (thr)->space ()->free_in_bytes ();
127+ size_t MutableNUMASpace::unsafe_max_tlab_alloc (Thread *ignored) const {
128+ size_t s = 0 ;
129+ for (LGRPSpace* ls : *lgrp_spaces ()) {
130+ s += ls->space ()->free_in_bytes ();
131+ }
132+ return s / (size_t )lgrp_spaces ()->length ();
138133}
139134
140135// Bias region towards the first-touching lgrp. Set the right page sizes.
@@ -442,13 +437,22 @@ void MutableNUMASpace::clear(bool mangle_space) {
442437 }
443438}
444439
445- HeapWord* MutableNUMASpace::cas_allocate (size_t size) {
446- Thread *thr = Thread::current ();
440+ MutableNUMASpace::LGRPSpace *MutableNUMASpace::lgrp_space_for_current_thread () const {
441+ const int lgrp_id = os::numa_get_group_id ();
442+ int lgrp_spaces_index = lgrp_spaces ()->find_if ([&](LGRPSpace* space) {
443+ return space->lgrp_id () == (uint)lgrp_id;
444+ });
447445
448- // Update the locality group to match where the thread actually is.
449- thr->update_lgrp_id ();
446+ if (lgrp_spaces_index == -1 ) {
447+ // Running on a CPU with no memory; pick another CPU based on %.
448+ lgrp_spaces_index = lgrp_id % lgrp_spaces ()->length ();
449+ }
450450
451- LGRPSpace *ls = lgrp_space_for_thread (thr);
451+ return lgrp_spaces ()->at (lgrp_spaces_index);
452+ }
453+
454+ HeapWord* MutableNUMASpace::cas_allocate (size_t size) {
455+ LGRPSpace *ls = lgrp_space_for_current_thread ();
452456 MutableSpace *s = ls->space ();
453457 HeapWord *p = s->cas_allocate (size);
454458 if (p != nullptr ) {
0 commit comments