-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b9388a
commit d4ae000
Showing
18 changed files
with
273 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/NamedTypeIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.ballerina.runtime.api.types; | ||
|
||
import io.ballerina.runtime.api.Module; | ||
|
||
public record NamedTypeIdentifier(Module pkg, String name) implements TypeIdentifier { | ||
|
||
public NamedTypeIdentifier { | ||
if (pkg == null) { | ||
throw new IllegalArgumentException("Package cannot be null"); | ||
} | ||
if (name == null) { | ||
throw new IllegalArgumentException("Name cannot be null"); | ||
} | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/TypeIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.ballerina.runtime.api.types; | ||
|
||
public interface TypeIdentifier { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...a-runtime/src/main/java/io/ballerina/runtime/api/types/semtype/TypeCheckCacheFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.ballerina.runtime.api.types.semtype; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public final class TypeCheckCacheFactory { | ||
|
||
private static final Map<TypeId, TypeCheckCache> cacheMap = new ConcurrentHashMap<>(); | ||
|
||
private TypeCheckCacheFactory() { | ||
} | ||
|
||
public static TypeCheckCache get(CacheableTypeDescriptor owner) { | ||
return cacheMap.computeIfAbsent(owner.typeId(), k -> new TypeCheckCache(owner)); | ||
} | ||
|
||
public static void resetCache() { | ||
cacheMap.forEach((k, v) -> v.reset()); | ||
cacheMap.clear(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/api/types/semtype/TypeId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.ballerina.runtime.api.types.semtype; | ||
|
||
public interface TypeId { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...rina-runtime/src/main/java/io/ballerina/runtime/internal/types/semtype/TypeIdFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.ballerina.runtime.internal.types.semtype; | ||
|
||
import io.ballerina.runtime.api.types.TypeIdentifier; | ||
import io.ballerina.runtime.api.types.semtype.TypeId; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.locks.ReadWriteLock; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
public class TypeIdFactory { | ||
|
||
private static final Map<TypeIdentifier, TypeId> typeIds = new HashMap<>(); | ||
private static final ReadWriteLock lock = new ReentrantReadWriteLock(); | ||
private static long nextId = 0; | ||
|
||
public static TypeId getTypeId(TypeIdentifier identifier) { | ||
lock.readLock().lock(); | ||
try { | ||
TypeId cached = typeIds.get(identifier); | ||
if (cached != null) { | ||
return cached; | ||
} | ||
} finally { | ||
lock.readLock().unlock(); | ||
} | ||
lock.writeLock().lock(); | ||
try { | ||
TypeId cached = typeIds.get(identifier); | ||
if (cached != null) { | ||
return cached; | ||
} | ||
TypeId typeId = new IntegerBasedTypeId(nextId++); | ||
typeIds.put(identifier, typeId); | ||
return typeId; | ||
} finally { | ||
lock.writeLock().unlock(); | ||
} | ||
} | ||
|
||
private record IntegerBasedTypeId(long id) implements TypeId { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.