Осмысление барьеров памятиJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Осмысление барьеров памяти

Сообщение Anonymous »

Я пытаюсь понять барьеры памяти на уровне, полезном для Java-программистов без блокировок. Я считаю, что этот уровень находится где-то между изучением летучих веществ и изучением работы с буферами хранения/загрузки из руководства по x86.

Я потратил некоторое время на чтение множества блогов и кулинарных книг и пришел к приведенному ниже описанию. Может ли кто-нибудь более знающий просмотреть краткое содержание и проверить, не пропустил ли я что-то или неправильно перечислил.

LFENCE:

Код: Выделить всё

Name             : LFENCE/Load Barrier/Acquire Fence
Barriers         : LoadLoad + LoadStore
Details          : Given sequence {Load1, LFENCE, Load2, Store1}, the
barrier ensures that Load1 can't be moved south and
Load2 and Store1 can't be moved north of the
barrier.
Note that Load2 and Store1 can still be reordered.

Buffer Effect    : Causes the contents of the LoadBuffer
(pending loads) to be processed for that CPU.This
makes program state exposed from other CPUs visible
to this CPU before Load2 and Store1 are executed.

Cost on x86      : Either very cheap or a no-op.
Java instructions: Reading a volatile variable, Unsafe.loadFence()
ЗАЩИТА

Код: Выделить всё

Name             : SFENCE/Store Barrier/Release Fence
Barriers         : StoreStore + LoadStore
Details          : Given sequence {Load1, Store1, SFENCE, Store2,Load2}
the barrier ensures that Load1 and Store1 can't be
moved south and Store2 can't be moved north of the
barrier.
Note that Load1 and Store1 can still be reordered AND
Load2 can be moved north of the barrier.
Buffer Effect    : Causes the contents of the StoreBuffer flushed to
cache for the CPU on which it is issued.
This will make program state visible to other CPUs
before Store2 and Load1 are executed.
Cost on x86      : Either very cheap or a no-op.
Java instructions: lazySet(), Unsafe.storeFence(), Unsafe.putOrdered*()
MFENCE

Код: Выделить всё

Name             : MFENCE/Full Barrier/Fence
Barriers         : StoreLoad
Details          : Obtains the effects of the other three barrier.
Given sequence {Load1, Store1, MFENCE, Store2,Load2},
the barrier ensures that Load1 and Store1 can't be
moved south and Store2 and Load2 can't be moved north
of the barrier.
Note that Load1 and Store1 can still be reordered AND
Store2 and Load2 can still be reordered.
Buffer Effect   : Causes the contents of the LoadBuffer (pending loads)
to be processed for that CPU.
AND
Causes the contents of the StoreBuffer flushed to
cache for the CPU on which it is issued.
Cost on x86     : The most expensive kind.
Java instructions: Writing to a volatile, Unsafe.fullFence(), Locks
Наконец, если и SFENCE, и MFENCE опустошают storeBuffer (делает кэш-линию недействительной и ждет подтверждений от другого процессора), почему одна операция не работает, а другая очень дорогая?

Спасибо

(перекрестная публикация с форума Google Mechanical Sympathy)>

Подробнее здесь: https://stackoverflow.com/questions/377 ... y-barriers
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»