1 /* |
1 /* |
2 * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2000, 2018, 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. |
25 package sun.jvm.hotspot.runtime; |
25 package sun.jvm.hotspot.runtime; |
26 |
26 |
27 import java.util.*; |
27 import java.util.*; |
28 import sun.jvm.hotspot.debugger.*; |
28 import sun.jvm.hotspot.debugger.*; |
29 import sun.jvm.hotspot.types.*; |
29 import sun.jvm.hotspot.types.*; |
|
30 import sun.jvm.hotspot.gc.shared.OopStorage; |
30 |
31 |
31 public class JNIHandles { |
32 public class JNIHandles { |
32 private static AddressField globalHandlesField; |
33 private static AddressField globalHandlesField; |
33 private static AddressField weakGlobalHandlesField; |
34 private static AddressField weakGlobalHandlesField; |
34 private static OopField deletedHandleField; |
|
35 |
35 |
36 static { |
36 static { |
37 VM.registerVMInitializedObserver(new Observer() { |
37 VM.registerVMInitializedObserver(new Observer() { |
38 public void update(Observable o, Object data) { |
38 public void update(Observable o, Object data) { |
39 initialize(VM.getVM().getTypeDataBase()); |
39 initialize(VM.getVM().getTypeDataBase()); |
44 private static synchronized void initialize(TypeDataBase db) { |
44 private static synchronized void initialize(TypeDataBase db) { |
45 Type type = db.lookupType("JNIHandles"); |
45 Type type = db.lookupType("JNIHandles"); |
46 |
46 |
47 globalHandlesField = type.getAddressField("_global_handles"); |
47 globalHandlesField = type.getAddressField("_global_handles"); |
48 weakGlobalHandlesField = type.getAddressField("_weak_global_handles"); |
48 weakGlobalHandlesField = type.getAddressField("_weak_global_handles"); |
49 deletedHandleField = type.getOopField("_deleted_handle"); |
|
50 |
49 |
51 } |
50 } |
52 |
51 |
53 public JNIHandles() { |
52 public JNIHandles() { |
54 } |
53 } |
55 |
54 |
56 public JNIHandleBlock globalHandles() { |
55 public OopStorage globalHandles() { |
57 Address handleAddr = globalHandlesField.getValue(); |
56 Address handleAddr = globalHandlesField.getValue(); |
58 if (handleAddr == null) { |
57 if (handleAddr == null) { |
59 return null; |
58 return null; |
60 } |
59 } |
61 return new JNIHandleBlock(handleAddr); |
60 return new OopStorage(handleAddr); |
62 } |
61 } |
63 |
62 |
64 public JNIHandleBlock weakGlobalHandles() { |
63 public OopStorage weakGlobalHandles() { |
65 Address handleAddr = weakGlobalHandlesField.getValue(); |
64 Address handleAddr = weakGlobalHandlesField.getValue(); |
66 if (handleAddr == null) { |
65 if (handleAddr == null) { |
67 return null; |
66 return null; |
68 } |
67 } |
69 return new JNIHandleBlock(handleAddr); |
68 return new OopStorage(handleAddr); |
70 } |
|
71 |
|
72 public OopHandle deletedHandle() { |
|
73 return deletedHandleField.getValue(); |
|
74 } |
|
75 |
|
76 public boolean isDeletedHandle(OopHandle handle) { |
|
77 return (handle != null && handle.equals(deletedHandle())); |
|
78 } |
69 } |
79 |
70 |
80 } |
71 } |