| 1 | /* ======================================================================== |
| 2 | * PlantUML : a free UML diagram generator |
| 3 | * ======================================================================== |
| 4 | * |
| 5 | * Project Info: http://plantuml.com |
| 6 | * |
| 7 | * If you like this project or if you find it useful, you can support us at: |
| 8 | * |
| 9 | * http://plantuml.com/patreon (only 1$ per month!) |
| 10 | * http://plantuml.com/paypal |
| 11 | * |
| 12 | * This file is part of Smetana. |
| 13 | * Smetana is a partial translation of Graphviz/Dot sources from C to Java. |
| 14 | * |
| 15 | * (C) Copyright 2009-2020, Arnaud Roques |
| 16 | * |
| 17 | * This translation is distributed under the same Licence as the original C program. |
| 18 | * |
| 19 | * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC |
| 20 | * LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0] |
| 21 | * |
| 22 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES |
| 23 | * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. |
| 24 | * |
| 25 | * You may obtain a copy of the License at |
| 26 | * |
| 27 | * http://www.eclipse.org/legal/epl-v10.html |
| 28 | * |
| 29 | * Unless required by applicable law or agreed to in writing, software |
| 30 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 31 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 32 | * See the License for the specific language governing permissions and |
| 33 | * limitations under the License. |
| 34 | * |
| 35 | */ |
| 36 | package smetana.core; |
| 37 | |
| 38 | public class Memory { |
| 39 | |
| 40 | public static __ptr__ malloc(Class theClass) { |
| 41 | JUtils.LOG("MEMORY::malloc " + theClass); |
| 42 | return JUtils.create(theClass, null); |
| 43 | } |
| 44 | |
| 45 | public static __ptr__ malloc(size_t size) { |
| 46 | return (__ptr__) size.malloc(); |
| 47 | } |
| 48 | |
| 49 | public static __ptr__ realloc(__ptr__ old, size_t size) { |
| 50 | throw new UnsupportedOperationException("" + old.getClass()); |
| 51 | } |
| 52 | |
| 53 | public static void free(Object arg) { |
| 54 | } |
| 55 | |
| 56 | public static int identityHashCode(CString data) { |
| 57 | if (data == null) { |
| 58 | return 0; |
| 59 | } |
| 60 | // int result = 2 * System.identityHashCode(data); |
| 61 | int result = data.getUid(); |
| 62 | Z.z().all.put(result, data); |
| 63 | // System.err.println("Memory::identityHashCode data=" + data); |
| 64 | // System.err.println("Memory::identityHashCode result=" + result + " " + Z.z().all.size()); |
| 65 | return result; |
| 66 | } |
| 67 | |
| 68 | public static Object fromIdentityHashCode(int hash) { |
| 69 | // System.err.println("Memory::fromIdentityHashCode hash=" + hash); |
| 70 | if (hash % 2 != 0) { |
| 71 | throw new IllegalArgumentException(); |
| 72 | } |
| 73 | Object result = Z.z().all.get(hash); |
| 74 | // System.err.println("Memory::fromIdentityHashCode result=" + result); |
| 75 | if (result == null) { |
| 76 | throw new UnsupportedOperationException(); |
| 77 | } |
| 78 | return result; |
| 79 | } |
| 80 | |
| 81 | } |