jdk/src/java.desktop/unix/classes/sun/awt/X11/UnsafeXDisposerRecord.java
author chegar
Wed, 11 Nov 2015 09:19:12 +0000
changeset 33674 566777f73c32
parent 25859 3317bb8137f4
permissions -rw-r--r--
8140606: Update library code to use internal Unsafe Reviewed-by: alanb, mchung, psandoz, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18178
diff changeset
     2
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
33674
566777f73c32 8140606: Update library code to use internal Unsafe
chegar
parents: 25859
diff changeset
    27
import jdk.internal.misc.Unsafe;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    28
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
class UnsafeXDisposerRecord implements sun.java2d.DisposerRecord {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    31
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.UnsafeXDisposerRecord");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    private static Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    final long[] unsafe_ptrs, x_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    volatile boolean disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    final Throwable place;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    public UnsafeXDisposerRecord(String name, long[] unsafe_ptrs, long[] x_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        this.unsafe_ptrs = unsafe_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        this.x_ptrs = x_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        if (XlibWrapper.isBuildInternal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            place = new Throwable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            place = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public UnsafeXDisposerRecord(String name, long ... unsafe_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        this.unsafe_ptrs = unsafe_ptrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        this.x_ptrs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (XlibWrapper.isBuildInternal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            place = new Throwable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            place = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            if (!disposed) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 5506
diff changeset
    62
                if (XlibWrapper.isBuildInternal && "Java2D Disposer".equals(Thread.currentThread().getName()) && log.isLoggable(PlatformLogger.Level.WARNING)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    if (place != null) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    64
                        log.warning(name + " object was not disposed before finalization!", place);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    66
                        log.warning(name + " object was not disposed before finalization!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                if (unsafe_ptrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    for (long l : unsafe_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                        if (l != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                            unsafe.freeMemory(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                if (x_ptrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    for (long l : x_ptrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                        if (l != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                            if (Native.getLong(l) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                XlibWrapper.XFree(Native.getLong(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                            unsafe.freeMemory(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                disposed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
}