001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt.X11;
026:
027: import sun.misc.Unsafe;
028: import java.util.logging.*;
029:
030: class UnsafeXDisposerRecord implements sun.java2d.DisposerRecord {
031: private static final Logger log = Logger
032: .getLogger("sun.awt.X11.UnsafeXDisposerRecord");
033: private static Unsafe unsafe = XlibWrapper.unsafe;
034: final long[] unsafe_ptrs, x_ptrs;
035: final String name;
036: volatile boolean disposed;
037: final Throwable place;
038:
039: public UnsafeXDisposerRecord(String name, long[] unsafe_ptrs,
040: long[] x_ptrs) {
041: this .unsafe_ptrs = unsafe_ptrs;
042: this .x_ptrs = x_ptrs;
043: this .name = name;
044: if (XlibWrapper.isBuildInternal) {
045: place = new Throwable();
046: } else {
047: place = null;
048: }
049: }
050:
051: public UnsafeXDisposerRecord(String name, long... unsafe_ptrs) {
052: this .unsafe_ptrs = unsafe_ptrs;
053: this .x_ptrs = null;
054: this .name = name;
055: if (XlibWrapper.isBuildInternal) {
056: place = new Throwable();
057: } else {
058: place = null;
059: }
060: }
061:
062: public void dispose() {
063: XToolkit.awtLock();
064: try {
065: if (!disposed) {
066: if (XlibWrapper.isBuildInternal
067: && "Java2D Disposer".equals(Thread
068: .currentThread().getName())
069: && log.isLoggable(Level.WARNING)) {
070: if (place != null) {
071: log
072: .log(
073: Level.WARNING,
074: name
075: + " object was not disposed before finalization!",
076: place);
077: } else {
078: log
079: .log(
080: Level.WARNING,
081: name
082: + " object was not disposed before finalization!");
083: }
084: }
085:
086: if (unsafe_ptrs != null) {
087: for (long l : unsafe_ptrs) {
088: if (l != 0) {
089: unsafe.freeMemory(l);
090: }
091: }
092: }
093: if (x_ptrs != null) {
094: for (long l : x_ptrs) {
095: if (l != 0) {
096: if (Native.getLong(l) != 0) {
097: XlibWrapper.XFree(Native.getLong(l));
098: }
099: unsafe.freeMemory(l);
100: }
101: }
102: }
103: disposed = true;
104: }
105: } finally {
106: XToolkit.awtUnlock();
107: }
108: }
109: }
|