EMMA Coverage Report (generated Wed Aug 29 00:03:59 CDT 2007)
[all classes][org.fuwjax.jon.type]

COVERAGE SUMMARY FOR SOURCE FILE [UnsafeInstantiator.java]

nameclass, %method, %block, %line, %
UnsafeInstantiator.java100% (1/1)75%  (3/4)56%  (20/36)46%  (6/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UnsafeInstantiator100% (1/1)75%  (3/4)56%  (20/36)46%  (6/13)
UnsafeInstantiator (): void 0%   (0/1)0%   (0/3)0%   (0/2)
create (Class): Object 100% (1/1)44%  (4/9)33%  (1/3)
getUnsafe (): Unsafe 100% (1/1)62%  (13/21)57%  (4/7)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)

1/*
2 * This file is part of JON.
3 *
4 * JON is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * JON is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 * 
17 * Copyright 2007 Michael Doberenz
18 */
19package org.fuwjax.jon.type;
20 
21import java.lang.reflect.Field;
22 
23import org.fuwjax.jon.ObjectAccessException;
24 
25/**
26 * DIRTY POOL: creates a new object using the Unsafe class.
27 * @author michaeldoberenz
28 */
29public final class UnsafeInstantiator{
30        private static final String UNSAFE_FIELD = "theUnsafe"; //$NON-NLS-1$
31        private static final sun.misc.Unsafe UNSAFE = getUnsafe();
32 
33        private UnsafeInstantiator(){
34                // utility class
35        }
36 
37        private static sun.misc.Unsafe getUnsafe(){
38                try{
39                        return sun.misc.Unsafe.getUnsafe();
40                }catch(RuntimeException e){
41                        try{
42                                final Field field = sun.misc.Unsafe.class.getDeclaredField(UNSAFE_FIELD);
43                                field.setAccessible(true);
44                                return (sun.misc.Unsafe)field.get(null);
45                        }catch(Exception ex){
46                                throw new RuntimeException(ex);
47                        }
48                }
49        }
50 
51        /**
52         * DIRTY POOL: creates using the unsafe object.
53         * @param type the class to create
54         * @return the newly created instance
55         * @throws ObjectAccessException if an object relationship cannot be restored
56         */
57        public static Object create(final Class<?> type) throws ObjectAccessException{
58                try{
59                        return UNSAFE.allocateInstance(type);
60                }catch(InstantiationException e){
61                        throw ObjectAccessException.Message.ObjectNotAllocated.exception(e);
62                }
63        }
64}

[all classes][org.fuwjax.jon.type]
EMMA 2.0.5312 (C) Vladimir Roubtsov