1 /* |
1 /* |
2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
577 // compare-and-exchange an unbiased header into the mark word of |
577 // compare-and-exchange an unbiased header into the mark word of |
578 // the object, meaning that no other thread has raced to acquire |
578 // the object, meaning that no other thread has raced to acquire |
579 // the bias of the object. |
579 // the bias of the object. |
580 markOop biased_value = mark; |
580 markOop biased_value = mark; |
581 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age()); |
581 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age()); |
582 markOop res_mark = (markOop) Atomic::cmpxchg_ptr(unbiased_prototype, obj->mark_addr(), mark); |
582 markOop res_mark = obj->cas_set_mark(unbiased_prototype, mark); |
583 if (res_mark == biased_value) { |
583 if (res_mark == biased_value) { |
584 return BIAS_REVOKED; |
584 return BIAS_REVOKED; |
585 } |
585 } |
586 } else if (mark->has_bias_pattern()) { |
586 } else if (mark->has_bias_pattern()) { |
587 Klass* k = obj->klass(); |
587 Klass* k = obj->klass(); |
592 // heuristics at this point so simply update the header with a |
592 // heuristics at this point so simply update the header with a |
593 // CAS. If we fail this race, the object's bias has been revoked |
593 // CAS. If we fail this race, the object's bias has been revoked |
594 // by another thread so we simply return and let the caller deal |
594 // by another thread so we simply return and let the caller deal |
595 // with it. |
595 // with it. |
596 markOop biased_value = mark; |
596 markOop biased_value = mark; |
597 markOop res_mark = (markOop) Atomic::cmpxchg_ptr(prototype_header, obj->mark_addr(), mark); |
597 markOop res_mark = obj->cas_set_mark(prototype_header, mark); |
598 assert(!(*(obj->mark_addr()))->has_bias_pattern(), "even if we raced, should still be revoked"); |
598 assert(!(*(obj->mark_addr()))->has_bias_pattern(), "even if we raced, should still be revoked"); |
599 return BIAS_REVOKED; |
599 return BIAS_REVOKED; |
600 } else if (prototype_header->bias_epoch() != mark->bias_epoch()) { |
600 } else if (prototype_header->bias_epoch() != mark->bias_epoch()) { |
601 // The epoch of this biasing has expired indicating that the |
601 // The epoch of this biasing has expired indicating that the |
602 // object is effectively unbiased. Depending on whether we need |
602 // object is effectively unbiased. Depending on whether we need |
607 // needing to revoke biases. |
607 // needing to revoke biases. |
608 if (attempt_rebias) { |
608 if (attempt_rebias) { |
609 assert(THREAD->is_Java_thread(), ""); |
609 assert(THREAD->is_Java_thread(), ""); |
610 markOop biased_value = mark; |
610 markOop biased_value = mark; |
611 markOop rebiased_prototype = markOopDesc::encode((JavaThread*) THREAD, mark->age(), prototype_header->bias_epoch()); |
611 markOop rebiased_prototype = markOopDesc::encode((JavaThread*) THREAD, mark->age(), prototype_header->bias_epoch()); |
612 markOop res_mark = (markOop) Atomic::cmpxchg_ptr(rebiased_prototype, obj->mark_addr(), mark); |
612 markOop res_mark = obj->cas_set_mark(rebiased_prototype, mark); |
613 if (res_mark == biased_value) { |
613 if (res_mark == biased_value) { |
614 return BIAS_REVOKED_AND_REBIASED; |
614 return BIAS_REVOKED_AND_REBIASED; |
615 } |
615 } |
616 } else { |
616 } else { |
617 markOop biased_value = mark; |
617 markOop biased_value = mark; |
618 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age()); |
618 markOop unbiased_prototype = markOopDesc::prototype()->set_age(mark->age()); |
619 markOop res_mark = (markOop) Atomic::cmpxchg_ptr(unbiased_prototype, obj->mark_addr(), mark); |
619 markOop res_mark = obj->cas_set_mark(unbiased_prototype, mark); |
620 if (res_mark == biased_value) { |
620 if (res_mark == biased_value) { |
621 return BIAS_REVOKED; |
621 return BIAS_REVOKED; |
622 } |
622 } |
623 } |
623 } |
624 } |
624 } |